#include <bits/stdc++.h>
#define pii pair<int,int>
using namespace std;
const int ma = 2e5 + 10;
int n,s0;
int a[ma],b[ma],ta[ma],tb[ma];
int n0[ma],n1[ma];
int id1[ma],id2[ma];
pii fa[ma];
struct sec {
	int l,r,id;
	bool operator < (const sec te)const {
		if(r != te.r) {
			return r < te.r;
		}
		return l < te.l;
	}
}s[ma];
bool cro(sec a,sec b) {
	return a.r >= b.l;
}
int clen(sec a,sec b) {
	return min(a.r,b.r) - max(a.l,b.l) + 1;
}
int main() {
	ios::sync_with_stdio(0),ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	int T;
	cin >> T;
	while(T--) {
		memset(n0,0,sizeof(n0));
		memset(n1,0,sizeof(n1));
		s0 = 0;
		cin >> n;
		char c;
		for(int i = 1; i <= n; i++) {
			cin >> c;
			a[i] = c == '1';
		}
		for(int i = 1; i <= n; i++) {
			cin >> c;
			b[i] = c == '1';
		}
		int st = 0;
		for(int i = 1; i <= n; i++) {
			cin >> c;
			ta[i] = c == '1';
			if(ta[i] && !st) {
				st = i;
			}
			if(!ta[i] && st) {
				if(i-st != 1) {
					s[++s0] = {st,i-1,1};
				} else {
					ta[st] = 0;
				}
				st = 0;
			}
		}
		if(st) {
			if(st != n) {
				s[++s0] = {st,n,1};
			} else {
				ta[n] = 0;
			}
			st = 0;
		}
		for(int i = 1; i <= n; i++) {
			cin >> c;
			tb[i] = c == '1';
			if(tb[i] && !st) {
				st = i;
			}
			if(!tb[i] && st) {
				if(i - st != 1) {
					s[++s0] = {st,i-1,2};
				} else {
					tb[st] = 0;
				}
				st = 0;
			}
		}
		if(st) {
			if(st != n) {
				s[++s0] = {st,n,2};
			} else {
				tb[n] = 0;
			}
			st = 0;
		}
		sort(s+1,s+s0+1);
		int ans = 0;
		for(int i = 1; i <= s0; i++) {
			int l = s[i].l,r = s[i].r,id = s[i].id;
			for(int j = l; j <= r; j++) {
				if(id == 1) {
					id1[j] = i;
					if(a[j] == 0) {
						n0[i]++;
					} else {
						n1[i]++;
					}
				} else {
					id2[j] = i;
					if(b[j] == 0) {
						n0[i]++;
					} else {
						n1[i]++;
					}
				}
			}
			for(int j = l; j <= r; j++) {
				if(ta[j] && tb[j])continue;
				if(id == 1) {
					if(b[j] == 0) {
						if(n0[i]) {
							n0[i]--,ans++;
						}
					} else {
						if(n1[i]) {
							n1[i]--,ans++;
						}
					}
				} else {
					if(a[j] == 0) {
						if(n0[i]) {
							n0[i]--,ans++;
						}
					} else {
						if(n1[i]) {
							n1[i]--,ans++;
						}
					}
				}
			}
		}
		for(int i = 1; i <= n; i++) {
			if(ta[i] && tb[i]) {
				int u = id1[i],v = id2[i],ct = clen(s[id1[i]],s[id2[i]]);
				if(n0[u] && n0[v] && ct) {
					ans++;
					n0[u]--,n0[v]--;
					continue;
				}
				if(n1[u] && n1[v] && ct) {
					ans++;
					n1[u]--,n1[v]--;
					continue;
				}
			}
		}
		for(int i = 1; i <= n; i++) {
			if(!ta[i] && !tb[i]) {
				ans += a[i] == b[i];
			}
		}
		cout << ans << '\n';
	}
	return 0;
}
