template<typename Type> inlinevoidread(Type& res) { res = 0; int ch = getchar(), flag = 0; while (!isdigit(ch)) flag |= ch == '-', ch = getchar(); while (isdigit(ch)) res = (res << 3) + (res << 1) + (ch ^ 48), ch = getchar(); res = flag ? -res : res; } template<typename Type, typename... Args> inlinevoidread(Type& res, Args&... y){ read(res), read(y...); }
int n; char str[N]; int s[2][N], t[2][N]; int pre[2][N], cnt[2][N][2];
intrt(int k, int x){ return pre[k][x] == x ? x : pre[k][x] = rt(k, pre[k][x]); }
inlinevoidmerge(int k, int x, int y) { int px = rt(k, x), py = rt(k, y); if (px == py) return; pre[k][py] = px, cnt[k][px][0] += cnt[k][py][0], cnt[k][px][1] += cnt[k][py][1]; }
voidsolve() { for (int k = 0; k < 2; k ++) for (int i = 0; i < N; i ++) pre[k][i] = i, cnt[k][i][0] = cnt[k][i][1] = 0;
read(n); for (int k = 0; k < 2; k ++) { scanf("%s", str + 1); for (int i = 1; i <= n; i ++) { s[k][i] = str[i] == '1'; cnt[k][i][s[k][i]] = 1; } } for (int k = 0; k < 2; k ++) { scanf("%s", str + 1); for (int i = 1; i <= n; i ++) { t[k][i] = str[i] == '1'; if (t[k][i] == 1 && t[k][i - 1] == 1) merge(k, i - 1, i); } }
int ans = 0; for (int cur = 1, i = rt(0, cur), j = rt(1, cur); cur <= n; cur ++, i = rt(0, cur), j = rt(1, cur)) { if (cnt[0][i][0] > 0 && cnt[1][j][0] > 0) ans ++, cnt[0][i][0] --, cnt[1][j][0] --; elseif (cnt[0][i][1] > 0 && cnt[1][j][1] > 0) ans ++, cnt[0][i][1] --, cnt[1][j][1] --; else { if (cnt[0][i][0] > 0) cnt[0][i][0] --, cnt[1][j][1] --; else cnt[0][i][1] --, cnt[1][j][0] --; } } cout << ans << '\n'; }
signedmain() { File("edit"); int T; read(T); while (T --) solve(); return0; }