#include <iostream>
#include <cstring>
#include <algorithm>
#include <queue>
//#define int long long
#define x first
#define y second
using namespace std;
typedef pair<int, int> PII;
const int N = 2e5 + 10;
bool Mst;
int n, a[N], b[N];
bool ok[N], ok2[N];
struct qwq {
	int l, r, c0, c1;
} p[N], q[N];
int idxa, idxb;
void work() {
	cin >> n, idxa = idxb = 0;
	memset(a, 0, sizeof a), memset(b, 0, sizeof b);
	memset(ok, 0, sizeof ok), memset(ok2, 0, sizeof ok2);
	for(int i = 0; i <= n + 1; i ++) p[i].l = p[i].r = p[i].c0 = p[i].c1 = 0;
	for(int i = 0; i <= n + 1; i ++) q[i].l = q[i].r = q[i].c0 = q[i].c1 = 0;
	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;ok[i] = ch - '0';}
	for(int i = 1; i <= n; i ++) {char ch; cin >> ch;ok2[i] = ch - '0';}
	for(int i = 1, j = 1, c0, c1; i <= n; i ++) {
		if(!ok[i]) {
			p[++ idxa] = {i, i, !a[i], a[i]};
			continue;
		}
		j = i - 1, c0 = c1 = 0;
		while(j < n && ok[j + 1] == 1) j ++, c0 += !a[j], c1 += a[j];
		p[++ idxa] = {i, j, c0, c1};
		i = j;
	}
	for(int i = 1, j = 1, c0, c1; i <= n; i ++) {
		if(!ok2[i]) {
			q[++ idxb] = {i, i, !b[i], b[i]};
			continue;
		}
		j = i - 1, c0 = c1 = 0;
		while(j < n && ok2[j + 1] == 1) j ++, c0 += !b[j], c1 += b[j];
		q[++ idxb] = {i, j, c0, c1};
		i = j;
	}
	p[idxa + 1].r = 1e9, q[idxb + 1].r = 1e9; 
	int ans = 0;
	for(int i = 1, j = 1; i <= idxa || j <= idxb;) {
		int len = min(p[i].r, q[j].r) - max(p[i].l, q[j].l) + 1;
		int cc0 = min(p[i].c0, q[j].c0);
		if(len >= cc0) ans += cc0, p[i].c0 -= cc0, q[j].c0 -= cc0, len -= cc0;
		else ans += len, p[i].c0 -= len, q[j].c0 -= len;
		int cc1 = min(p[i].c1, q[j].c1);
		if(len >= cc1) ans += cc1, p[i].c1 -= cc1, q[j].c1 -= cc1, len -= cc1;
		else ans += len, p[i].c1 -= len, q[j].c1 -= len;
		if(i <= idxa && p[i].r < q[j].r) i ++;
		else j ++;
//		cout << i << ' ' << j << ' ' << p[i].l << ' ' << p[i].r << ' ' << q[j].l << ' ' << q[j].r << '\n';
	} 
	cout << ans << '\n';
}
bool Med;
signed main() {
	freopen("edit.in", "r", stdin);
	freopen("edit.out", "w", stdout);
	ios::sync_with_stdio(0), cin.tie(0);
	cerr << (abs(&Mst - &Med) / 1048576.0) << "Mb\n";
	int T = 1; cin >> T;
	while(T --) work();
	
	return 0;
}

