#include <bits/stdc++.h>
#define FASTIO ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define rep(i, l, r) for (int i = l; i <= r; i++)
#define per(i, r, l) for (int i = r; i >= l; i--)
#define LL long long
#define ULL unsigned long long
#define PII pair<int,int>
using namespace std;
const int N = 1e5+5;
int n, cnts[2], cntt[2], ans;
string s,t,a,b;
bool spA;
int ss1[N], ss2[N], tts[2], ttt[2];
void dfs(int x) {
if (x > n) {
memset(tts, 0, sizeof tts);
memset(ttt, 0, sizeof ttt);
memset(cnts, 0, sizeof cnts);
memset(cntt, 0, sizeof cntt);
rep(i, 1, n) {
if (a[i-1] == '0') {
if (tts[0] != cnts[0] || tts[1] != cnts[1] || s[i-1]!=ss1[i]+'0') return;
tts[0] = tts[1] = cnts[0] = cnts[1] = 0;
} else tts[ss1[i]]++,cnts[s[i-1]-'0']++;
if (b[i-1] == '0') {
if (ttt[0] != cntt[0] || ttt[1] != cntt[1] || t[i-1]!=ss2[i]+'0') return;
ttt[0] = ttt[1] = cntt[0] = cntt[1] = 0;
} else cntt[t[i-1]-'0']++, ttt[ss2[i]] ++;
}
if (cntt[0] != ttt[0] || cntt[1] != ttt[1] || tts[0] != cnts[0] || tts[1] != cnts[1]) return;
int res = 0;
rep(i, 1, n)
res += ss1[i]==ss2[i];
ans = max(ans, res);
return;
}
ss1[x] = 1, ss2[x] = 1;
dfs(x+1);
ss1[x] = 0, ss2[x] = 0;
dfs(x+1);
ss1[x] = 1, ss2[x] = 0;
dfs(x+1);
ss1[x] = 0, ss2[x] = 1;
dfs(x+1);
}
inline void slove() {
cin >> n;
cin >> s;
cin >> t >> a >> b;
spA = true;
rep(i, 2, n)
spA &= s[i-1]==s[0];
ans = 0;
if (n <= 10) {
dfs(1);
cout << ans << '\n';
} else if (spA) {
rep(i, 1, n)
if (t[i-1]==s[i-1])
ans++;
cout << ans << '\n';
} else if (a == b) {
cntt[0] = cntt[1] = cnts[0] = cnts[1] = 0;
rep(i, 1, n) {
if (a[i-1] == '0') {
ans += min(cnts[0], cntt[0])+min(cnts[1], cntt[1])+(s[i-1]==t[i-1]);
cntt[0] = cntt[1] = cnts[0] = cnts[1] = 0;
} else cntt[t[i-1]-'0']++, cnts[s[i-1]-'0']++;
}
cout << ans+min(cnts[0], cntt[0])+min(cnts[1], cntt[1]) << '\n';
} else {
rep(i, 1, n)
if (a[i-1] == '1')
cnts[s[i-1]-'0']++;
rep(i, 1, n)
if (b[i-1] == '1')
cnts[t[i-1]-'0']++;
ans = 0;
rep(i, 1, n) {
if (a[i-1]=='0' && b[i-1]=='0') ans += s[i-1]==t[i-1];
else if (a[i-1]=='1' && b[i-1]=='1') {
if (cnts[0] > 0 && cntt[0] > 0) {
cnts[0]--, cntt[0]--;
ans++;
} else if (cnts[1] > 0 && cntt[1] > 0) {
cnts[1]--, cntt[1]--;
ans++;
} else {
if (cnts[1] > 0) cnts[1]--;
else cnts[0]--;
if (cntt[1] > 0) cntt[1]--;
else cntt[0]--;
}
} else if (b[i-1] == '0') {
int ch = t[i-1]-'0';
if (cnts[ch] > 0) cnts[ch]--, ans++;
else cnts[ch^1]--, ans++;
} else if (a[i-1] == '0') {
int ch = s[i-1]-'0';
if (cntt[ch] > 0) cntt[ch]--, ans++;
else cntt[ch^1]--, ans++;
}
}
cout << ans << '\n';
}
}
int main() {
FASTIO;
freopen("edit.in", "r", stdin);
freopen("edit.out", "w", stdout);
int _;
cin >> _;
while (_--) slove();
return 0;
}