#include<bits/stdc++.h>
#define Yzl unsigned long long
#define fi first
#define se second
#define pi pair<int,int>
#define mp make_pair
#define pb emplace_back
#define lob lower_bound
#define upb upper_bound
typedef long long LL;

using namespace std;

const Yzl Lty=20120712;

const int MAXN=1e5+10;
int n,ans;
char a[MAXN],b[MAXN],c[MAXN],d[MAXN];
struct itv {
	int l,r,a0,a1;
}x[MAXN],y[MAXN];
int l1,l2;
void calc1(int i) { if(i>l1) return ;
	for(int j=x[i].l;j<=x[i].r;++j) {
		if(d[j]=='0') {
			if(b[j]=='0'&&x[i].a0) ++ans,--x[i].a0;
			if(b[j]=='1'&&x[i].a1) ++ans,--x[i].a1;
		}
	}
}
void calc2(int i) { if(i>l2) return ;
	for(int j=y[i].l;j<=y[i].r;++j) {
		if(c[j]=='0') {
			if(a[j]=='0'&&y[i].a0) ++ans,--y[i].a0;
			if(a[j]=='1'&&y[i].a1) ++ans,--y[i].a1;
		}
	}
}
void vmain() {
	scanf("%d",&n);
	scanf("%s%s%s%s",a+1,b+1,c+1,d+1); ans=l1=l2=0;
	for(int i=1;i<=n;++i) {
		if(c[i]=='1') {
			x[++l1]=(itv){i,i,0,0};
			for(int j=i;j<=n;++j) {
				if(c[j]=='0') break;
				x[l1].r=j; if(a[j]=='1') ++x[l1].a1; else ++x[l1].a0;
			} i=x[l1].r;
		}
	}
	for(int i=1;i<=n;++i) {
		if(d[i]=='1') {
			y[++l2]=(itv){i,i,0,0};
			for(int j=i;j<=n;++j) {
				if(d[j]=='0') break;
				y[l2].r=j; if(b[j]=='1') ++y[l2].a1; else ++y[l2].a0;
			} i=y[l2].r;
		}
	}
	for(int i=1;i<=n;++i) if(c[i]=='0'&&d[i]=='0') ans+=(a[i]==b[i]);
	for(int i=1;i<=l1;++i) calc1(i);
	for(int i=1;i<=l2;++i) calc2(i);
	int p1=1,p2=1;
	while(p1<=l1&&p2<=l2) {
		int aa=min(x[p1].a0,y[p2].a0),bb=min(x[p1].a1,y[p2].a1);
		int lp=max(0,min(x[p1].r,y[p2].r)-max(x[p1].l,y[p2].l)+1);
		aa=min(aa,lp); bb=min(bb,lp);
		ans+=aa+bb; x[p1].a0-=aa; y[p2].a0-=aa; x[p1].a1-=bb; y[p2].a1-=bb;
		if(x[p1].r<=y[p2].r) ++p1;
		else ++p2;
	}
	printf("%d\n",ans);
}
int main () {
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	int T=1; scanf("%d",&T); while(T--) vmain();
	return 0;
}

