#include<bits/stdc++.h>

using namespace std;

//¼ÇµÃ¶à²âÇå¿Õ£¡£¡£¡£¡ 

int t,n;
int a[200010];
int b[200010];
int c[200010];
int d[200010];
int ans;

int tree1[200010];
int tree2[200010];

int v1[200010];
int v2[200010];
int cnt1,cnt2;

int lowbit(int x){
	return x&(-x);
}

void update1(int x,int v){
	for(int i=x;i<=n;i+=lowbit(i)){
		tree1[i]+=v;
	}
}

void update2(int x,int v){
	for(int i=x;i<=n;i+=lowbit(i)){
		tree2[i]+=v;
	}
}

int query1(int x){
	if(x==0) return 0;
	int sum=0;
	for(int i=x;i>=1;i-=lowbit(i)){
		sum+=tree1[i];
	}
	return sum;
}

int query2(int x){
	if(x==0) return 0;
	int sum=0;
	for(int i=x;i>=1;i-=lowbit(i)){
		sum+=tree2[i];
	}
	return sum;
}

int main(){
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	
	//freopen("qwqaa.out","w",stdout);
	
	scanf("%d",&t);
	while(t--){
		cnt1=cnt2=ans=0;
		scanf("%d",&n);
		for(int i=1;i<=n;i++){
			scanf("%1d",&a[i]);
			update1(i,a[i]);
		}
		for(int i=1;i<=n;i++){
			scanf("%1d",&b[i]);
			update2(i,b[i]);
		}
		for(int i=1;i<=n;i++){
			scanf("%1d",&c[i]);
			if(c[i]==0){
				v1[++cnt1]=i;
			}
		}
		v1[++cnt1]=n+1;
		for(int i=1;i<=n;i++){
			scanf("%1d",&d[i]);
			if(d[i]==0){
				v2[++cnt2]=i;
			}
		}
		v2[++cnt2]=n+1;
		
		//for(int x:v1) printf("%d ",x);
		//puts("");
		
		for(int i=1;i<=n;i++){
			if(a[i]!=b[i]){
				int now1=lower_bound(v1+1,v1+1+cnt1,i)-v1;
				int now2=lower_bound(v2+1,v2+1+cnt2,i)-v2;
				if(a[i]==0){
					int l=i,r=v1[now1];
					//a[r]=b[r]=1;
					while(l<r){
						if(l==1&&query1(l)==1){
							break;
						}
						int mid=(l+r)/2;
						if(query1(mid)>query1(i-1)){
							r=mid;
						}
						else l=mid+1;
					}
					//printf("qwq %d %d\n",i,l);
					//if(i==4) printf("aaaa %d %d\n",query);
					
					//printf("%d %d %d\n",i,l,v1[now1]);
					
					//if(i==2){
						//for(int i=1;i<=n;i++) printf("%d ",query1(i)-query1(i-1));
						//puts("");
					//}
					
					if(l<v1[now1]){
						ans++;
						//printf("aaaa %d\n",i);
						swap(a[i],a[l]);
						update1(i,1);
						update1(l,-1);
					}
					
					
					
					else{
						int l=i,r=v2[now2];
						while(l<r){
							if(l==1&&query2(l)==0){
								break;
							}
							int mid=(l+r)/2;
							if(query2(mid)-query2(i-1)!=(mid-i+1)){
								r=mid;
							}
							else l=mid+1;
						}
						//printf("qwq %d %d %d\n",i,l,v2[now2]);
						//if(i==4) printf("aaaa %d %d\n",query);
						
						if(l<v2[now2]){
							ans++;
							//printf("baaa %d\n",i);
							swap(b[i],b[l]);
							update2(i,-1);
							update2(l,1);
						}
					}
					
					
				}
				
				
				
				
				
				else{
					int l=i,r=v2[now2];
					while(l<r){
						if(l==1&&query2(l)==1){
							break;
						}
						int mid=(l+r)/2;
						if(query2(mid)>query2(i-1)){
							r=mid;
						}
						else l=mid+1;
					}
					//printf("qwq %d %d\n",i,l);
					//if(i==4) printf("aaaa %d %d\n",query);
					
					if(l<v2[now2]){
						ans++;
						//printf("caaa %d\n",i);
						swap(b[i],b[l]);
						update2(i,1);
						update2(l,-1);
					}
					else{
						int l=i,r=v1[now1];
						//a[r]=b[r]=1;
						while(l<r){
							if(l==1&&query1(l)==0){
								break;
							}
							int mid=(l+r)/2;
							if(query1(mid)-query1(i-1)!=(mid-i+1)){
								r=mid;
							}
							else l=mid+1;
						}
						//printf("qwq %d %d\n",i,l);
						//if(i==4) printf("aaaa %d %d\n",query);
						
						if(l<v1[now1]){
							ans++;
							//printf("daaa %d\n",i);
							swap(a[i],a[l]);
							update1(i,-1);
							update1(l,1);
						}
					}
				}
			}
			else{
				//printf("%d ",i);
				//puts("adfjbk");
				ans++;
			}
		}
		printf("%d\n",ans);
		
		for(int i=1;i<=n;i++){
			tree1[i]=0;
			tree2[i]=0;
		}
	}
	return 0;
}
/*
1
6
011101
111010
111010
101101

1
6
111010
011101
111010
101101

1
9
101111111
100111000
110111011
011111111
*/
