#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 3;
int T, n, a[maxn], b[maxn], s[maxn], t[maxn];

namespace Slv0 {
	int x[maxn], y[maxn];
	int a0, a1, b0, b1;
	int res;
	int check() {
		int lst = 0;
		for (int i = 1; i <= n + 1; i++) {
			if (s[i] == 0) {
				int c0 = 0, c1 = 0, d0 = 0, d1 = 0;
				for (int j = lst + 1; j < i; j++) {
					c0 += (a[j] == 0);
					d0 += (x[j] == 0);
				}
				if (c0 != d0) return 0;
				lst = i;
				if (a[i] != x[i]) return 0;
			}
		}
		lst = 0;
		for (int i = 1; i <= n + 1; i++) {
			if (t[i] == 0) {
				int c0 = 0, c1 = 0, d0 = 0, d1 = 0;
				for (int j = lst + 1; j < i; j++) {
					c0 += (b[j] == 0);
					d0 += (y[j] == 0);
				}
				if (c0 != d0) return 0;
				lst = i;
				if (b[i] != y[i]) return 0;
			}
		}
		int cur = 0;
		for (int i = 1; i <= n; i++) cur += (x[i] == y[i]);
		return cur; 
	}
	void dfs1(int c, int d, int e) {
		if (d > a0 || e > a1) return ;
		if (c == n + 1) {
			res = max(res, check());
			return ;
		}
		x[c] = 0; dfs1(c + 1, d + 1, e);
		x[c] = 1; dfs1(c + 1, d, e + 1);
	}
	void dfs2(int c, int d, int e) {
		if (d > b0 || e > b1) return ;
		if (c == n + 1) {
			dfs1(1, 0, 0);
			return ;
		}
		y[c] = 0; dfs2(c + 1, d + 1, e);
		y[c] = 1; dfs2(c + 1, d, e + 1);
	}
	void solve() {
		res = a0 = b0 = a1 = b1 = 0;
		for (int i = 1; i <= n; i++) {
			a0 += (a[i] == 0), b0 += (b[i] == 0); 
			a1 += (a[i] == 1), b1 += (b[i] == 1); 
		}
		dfs2(1, 0, 0);
		cout << res << '\n';
		memset(x, 0, sizeof x);
		memset(y, 0, sizeof y);
	}
}

namespace Slv1 {
	void solve() {
		int res = 0;
		for (int i = 1; i <= n; i++) {
			res += (b[i] == a[1]);
		}
		cout << res << '\n';
	}
}

namespace Slv2 {
	void solve() {
		int lst = 0, res = 0;
		for (int i = 1; i <= n + 1; i++) {
			if (s[i] == 0) {
				int c0 = 0, c1 = 0, d0 = 0, d1 = 0;
				for (int j = lst + 1; j < i; j++) {
					c0 += (a[j] == 0), c1 += (a[j] == 1);
					d0 += (b[j] == 0), d1 += (b[j] == 1);
				}
				res += min(c0, d0) + min(c1, d1);
				lst = i;
				if (i != n + 1) res += (a[i] == b[i]); 
			}
		}
		cout << res << '\n';
	}
}

void solve(int id) {
	cin >> n;
	for (int i = 1; i <= n; i++) {
		char ch; cin >> ch; a[i] = ch - '0';
	}
	for (int i = 1; i <= n; i++) {
		char ch; cin >> ch; b[i] = ch - '0';
	}
	for (int i = 1; i <= n; i++) {
		char ch; cin >> ch; s[i] = ch - '0';
	}
	for (int i = 1; i <= n; i++) {
		char ch; cin >> ch; t[i] = ch - '0';
	}
	bool A = 1, B = 1, C = 1; int s1 = 0, s2 = 0;
	for (int i = 1; i <= n; i++) {
		if (a[i] != a[1]) A = 0;
		if (s[i] != t[i]) B = 0; 
		s1 += s[i], s2 += t[i];
	}
	if (s1 != n - 1 || s2 != n - 1) C = 0;
	if (A) Slv1::solve();
	else if (B) Slv2::solve();
	else if (n <= 10) Slv0::solve();
	else cout << n << '\n';
	memset(a, 0, sizeof a);
	memset(b, 0, sizeof b);
	memset(s, 0, sizeof s);
	memset(t, 0, sizeof t);
} 
int main() {
	freopen("edit.in", "r", stdin);
	freopen("edit.out", "w", stdout);
	int T; cin >> T;
	for (int i = 1; i <= T; i++) solve(i);
} 
// 打的最差的一次  一个题都没切  下个赛季再见 qaq 
// luogu uid : 752017 name : buowen123 
/*
时间过得真快, 转眼间 NOIP 就到来了
考完后停课就结束了 就要回去学 whk 了
希望今年一等线能低一点吧 
T2 应该是会的，我的思路大概没有假 
就是最暴力的 dp[i][0/1][0/1] 表示前 i 个标记
i 处于一条“真链”/“不定链”上，且这条链搭在/没打在 i 处
链表示传递关系 x[i]=a -> x[i+1]=b -> x[i+2]=c...，
而链是否真取决于一元关系 不过我没时间写了 
代码实现能力还是太弱了啊 
就这样吧 祝大家未来可期 
*/ 
