#include<bits/stdc++.h>
using namespace std;
#define ld cin
#define jyt cout
#define ll long long
#define ull unsigned long long
#define REP(i, l, r) for (int i = l; i <= r; ++i)
#define PER(i, l, r) for (int i = l; i >= r; --i)
const int N = 2e5 + 7;
const int inf = 1e9 + 7;
const ll linf = 1e18 + 7;
const int P = 998244353;
namespace JoKing {
int T, n;
string S1, T1, S2, T2;
struct Wyy {
int l, r, c0, c1, op;
} p1[N], p2[N];
signed main() {
ld >> T;
while (T--) {
ld >> n >> S1 >> S2 >> T1 >> T2;
S1 = " " + S1, S2 = " " + S2, T1 = " " + T1, T2 = " " + T2;
int pos1 = 0, pos2 = 0, L1 = 0, L2 = 0, c10 = 0, c11 = 0, c20 = 0, c21 = 0;
REP(i, 1, n) {
if (T1[i] == '0') p1[++pos1] = (Wyy) {L1 + 1, i, c10, c11, (S1[i] == '1')}, L1 = i, c10 = c11 = 0;
else c10 += (S1[i] == '0'), c11 += (S1[i] == '1');
if (T2[i] == '0') p2[++pos2] = (Wyy) {L2 + 1, i, c20, c21, (S2[i] == '1')}, L2 = i, c20 = c21 = 0;
else c20 += (S2[i] == '0'), c21 += (S2[i] == '1');
}
if (L1 != n) p1[++pos1] = (Wyy) {L1 + 1, n, c10, c11, -1};
if (L2 != n) p2[++pos2] = (Wyy) {L2 + 1, n, c20, c21, -1};
int tot1 = 1, tot2 = 1, Ans = 0;
while (tot1 <= pos1 && tot2 <= pos2) {
if (p1[tot1].r > p2[tot2].r) {
if (p2[tot2].op) ++p2[tot2].c1;
else ++p2[tot2].c0;
int dlt0 = min(p2[tot2].c0, p1[tot1].c0), dlt1 = min(p2[tot2].c1, p1[tot1].c1);
p2[tot2].c0 -= dlt0, p1[tot1].c0 -= dlt0;
p2[tot2].c1 -= dlt1, p1[tot1].c1 -= dlt1;
Ans += dlt0 + dlt1;
if (p2[tot2].c0) p1[tot1].c1 -= p2[tot2].c0;
if (p2[tot2].c1) p1[tot1].c0 -= p2[tot2].c1;
++tot2;
} else if (p1[tot1].r == p2[tot2].r) {
if (p1[tot1].op == -1 || p2[tot2].op == -1) {
if (p2[tot2].op != -1) {
if (p2[tot2].op) ++p2[tot2].c1;
else ++p2[tot2].c0;
}
if (p1[tot1].op != -1) {
if (p1[tot1].op) ++p1[tot1].c1;
else ++p1[tot1].c0;
}
} else Ans += (p1[tot1].op == p2[tot2].op);
int dlt0 = min(p2[tot2].c0, p1[tot1].c0), dlt1 = min(p2[tot2].c1, p1[tot1].c1);
p2[tot2].c0 -= dlt0, p1[tot1].c0 -= dlt0;
p2[tot2].c1 -= dlt1, p1[tot1].c1 -= dlt1;
Ans += dlt0 + dlt1;
++tot1, ++tot2;
} else {
if (p1[tot1].op) ++p1[tot1].c1;
else ++p1[tot1].c0;
int dlt0 = min(p2[tot2].c0, p1[tot1].c0), dlt1 = min(p2[tot2].c1, p1[tot1].c1);
p2[tot2].c0 -= dlt0, p1[tot1].c0 -= dlt0;
p2[tot2].c1 -= dlt1, p1[tot1].c1 -= dlt1;
Ans += dlt0 + dlt1;
if (p1[tot1].c0) p2[tot2].c1 -= p1[tot1].c0;
if (p1[tot1].c1) p2[tot2].c0 -= p1[tot1].c1;
++tot1;
}
}
jyt << Ans << '\n';
}
return 0;
}
}
signed main() {
freopen("edit.in", "r", stdin);
freopen("edit.out", "w", stdout);
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
JoKing::main(); return 0;
}