//NOIP2024 RP++
//不要挂分，不要挂分，不要挂分
//debug 深入思考，只靠样例与自己 
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair <int, int> pii;
typedef long double wisdom;

const int N = 4e5 + 5;
int A[N], B[N], s[N], t[N], bela[N], belb[N], cnta[N][2], cntb[N][2];
void solve() {
	int n, ans = 0, idxa = 1, idxb = 1; scanf("%d", &n);
	for (int i = 1; i <= n + 5; i++) cnta[i][0] = cnta[i][1] = cntb[i][0] = cntb[i][1] = 0;
	for (int i = 1; i <= n; i++) scanf("%1d", &A[i]);
	for (int i = 1; i <= n; i++) scanf("%1d", &B[i]);
	for (int i = 1; i <= n; i++) scanf("%1d", &s[i]);
	for (int i = 1; i <= n; i++) scanf("%1d", &t[i]);
	for (int i = 1, fl = false; i <= n; i++) {if (!s[i]) idxa++, fl = true; else if (fl) idxa++, fl = false; bela[i] = idxa, cnta[idxa][A[i]]++;}
	for (int i = 1, fl = false; i <= n; i++) {if (!t[i]) idxb++, fl = true; else if (fl) idxb++, fl = false; belb[i] = idxb, cntb[idxb][B[i]]++;}
	for (int i = 1; i <= n; i++) {
		if (!s[i]) {if (cntb[belb[i]][A[i]]) cntb[belb[i]][A[i]]--, ans++; else cntb[belb[i]][A[i] ^ 1]--;}
		else if (!t[i]) {if (cnta[bela[i]][B[i]]) cnta[bela[i]][B[i]]--, ans++; else cnta[bela[i]][B[i] ^ 1]--;}
	}
	for (int i = 1; i <= n; i++) if (s[i] && t[i]) {
		if (cnta[bela[i]][0] && cntb[belb[i]][0]) ans++, cnta[bela[i]][0]--, cntb[belb[i]][0]--;
		else if (cnta[bela[i]][1] && cntb[belb[i]][1]) ans++, cnta[bela[i]][1]--, cntb[belb[i]][1]--;
		else (cnta[bela[i]][0] ? cnta[bela[i]][0]-- : cnta[bela[i]][1]--), (cntb[belb[i]][0] ? cntb[belb[i]][0]-- : cntb[belb[i]][1]--);
	}
	printf("%d\n", ans);
}
int main() {
	freopen("edit.in", "r", stdin); freopen("edit.out", "w", stdout);
	int T; scanf("%d", &T); while (T--) solve();
	return 0;
}
