#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define fi first
#define se second
#define pb emplace
#define pbb emplace_back
const int maxn = 1e5+50;
int T, n, tt, ans;
char c;
bool s1[maxn], s2[maxn], t1[maxn], t2[maxn];
int an1[maxn], an2[maxn], su1[maxn], su2[maxn];
vector<pii> sw1, sw2;
vector<pii> la1, la2;
int wh1[maxn], wh2[maxn];
void dfs2(int x) {
	if (x > n) {
		int an = 0;
		for (int i = 1; i <= n; ++i) {
			if (~an1[i] && ~an2[i] && !(an1[i] ^ an2[i])) ++an;
		}
		ans = max(an, ans);
		return;
	}
	if (!t2[x]) {
		dfs2(x + 1);
		return;
	}
	if (la2[wh2[x]].fi) {
		an2[x] = 1;
		--la2[wh2[x]].fi;
		dfs2(x + 1);
		++la2[wh2[x]].fi;
	} if (la2[wh2[x]].se) {
		an2[x] = 0;
		--la2[wh2[x]].se;
		dfs2(x + 1);
		++la2[wh2[x]].se;
	}
}
void dfs1(int x) {
	if (x > n) {
		dfs2(1);
		return;
	}
	if (!t1[x]) {
		dfs1(x + 1);
		return;
	}
	if (la1[wh1[x]].fi) {
		an1[x] = 1;
		--la1[wh1[x]].fi;
		dfs1(x + 1);
		++la1[wh1[x]].fi;
	} if (la1[wh1[x]].se) {
		an1[x] = 0;
		--la1[wh1[x]].se;
		dfs1(x + 1);
		++la1[wh1[x]].se;
	}
}
int main() {
	freopen("edit.in", "r", stdin);
	freopen("edit.out", "w", stdout);
	ios::sync_with_stdio(false);
	cin.tie(nullptr), cout.tie(nullptr);
	for (cin >> T; T--;) {
		cin >> n;
		for (int i = 1; i <= n; ++i)
			cin >> c, s1[i] = c - 48, su1[i] = su1[i - 1] + s1[i], an1[i] = -1;
		for (int i = 1; i <= n; ++i)
			cin >> c, s2[i] = c - 48, su2[i] = su2[i - 1] + s2[i], an2[i] = -1;
		sw1.clear(), sw2.clear();
		for (int i = 1; i <= n; ++i) {
			cin >> c, t1[i] = c - 48;
			if (!t1[i] && tt) sw1.pbb(tt, i - 1), tt = 0;
			else if (t1[i]) tt = (tt ? tt : i);
			if (!t1[i]) an1[i] = s1[i];
		} if (tt) sw1.pbb(tt, n), tt = 0;
		for (int i = 1; i <= n; ++i) {
			cin >> c, t2[i] = c - 48;
			if (!t2[i] && tt) sw2.pbb(tt, i - 1), tt = 0;
			else if (t2[i]) tt = (tt ? tt : i);
			if (!t2[i]) an2[i] = s2[i];
		} if (tt) sw2.pbb(tt, n), tt = 0;
		if (su1[n] == n || !su1[n] || su2[n] == n || !su2[n]) {
			ans = 0;
			for (int i = 1; i <= n; ++i)
				if (!(s1[i] ^ s2[i])) ++ans;
			cout << ans << '\n';
			continue;
		}
		if (sw1 == sw2) {
			ans = 0;
			for (int i = 1; i <= n; ++i)
				if (!t1[i] && !(s1[i] ^ s2[i])) ++ans;
			for (int i = 0, l, r, sz, t1, t2; i < sw1.size(); ++i) {
				l = sw1[i].fi, r = sw1[i].se, sz = r - l + 1, t1 = su1[r] - su1[l - 1], t2 = su2[r] - su2[l - 1];
				ans += min(t1, t2) + min(sz - t1, sz - t2);
			}
			cout << ans << '\n';
			continue;
		}
		for (int i = 0, l, r; i < sw1.size(); ++i) {
			l = sw1[i].fi, r = sw1[i].se;
			if (l == r || su1[r] - su1[l - 1] == r - l + 1 || su1[r] - su1[l - 1] == 0) {
				sw1.erase(sw1.begin() + i);
				for (int j = l; j <= r; ++j)
					t1[j] = 0, an1[j] = s1[j];
				--i;
			}
		}
		for (int i = 0, l, r; i < sw2.size(); ++i) {
			l = sw2[i].fi, r = sw2[i].se;
			if (l == r || su2[r] - su2[l - 1] == r - l + 1 || su2[r] - su2[l - 1] == 0) {
				sw2.erase(sw2.begin() + i);
				for (int j = l; j <= r; ++j)
					t2[j] = 0, an2[j] = s2[j];
				--i;
			}
		}
		la1.clear(), la2.clear();
		for (int i = 0, l, r; i < sw1.size(); ++i) {
			l = sw1[i].fi, r = sw1[i].se;
			la1.pbb(su1[r] - su1[l - 1], r - l + 1 - su1[r] + su1[l - 1]);
			for (int j = l; j <= r; ++j)
				wh1[j] = i;
		}
		for (int i = 0, l, r; i < sw2.size(); ++i) {
			l = sw2[i].fi, r = sw2[i].se;
			la2.pbb(su2[r] - su2[l - 1], r - l + 1 - su2[r] + su2[l - 1]);
			for (int j = l; j <= r; ++j)
				wh2[j] = i;
		}
		ans = 0;
		dfs1(0);
		cout << ans << '\n';
	}
	return 0;
}
