#include<bits/stdc++.h>
using namespace std;

const int N=1e5+5;
int s1[N],s2[N];
bool f1[N],f2[N];

int main(){
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	int T;
	scanf("%d",&T);
	while(T--){
		int n;
		scanf("%d",&n);
		char c;
		for(int i=1;i<=n;++i){cin>>c;s1[i]=c-'0';}
		for(int i=1;i<=n;++i){cin>>c;s2[i]=c-'0';}
		for(int i=1;i<=n;++i){cin>>c;f1[i]=c-'0';}
		for(int i=1;i<=n;++i){cin>>c;f2[i]=c-'0';}
		
		int l=0,r=0,sum=0;
		for(int i=1;i<=n;++i) if(s1[i]==0){
				++sum,l=i;
			}
		if(sum==1){
			for(int i=1;i<=n;++i) if(s2[i]==0){
				++sum,r=i;
			}
			if(sum==2){
				if(l<r){
					while(f1[l]&&l<n) ++l;
					while(f2[r]&&r>1) --r;
					if(l>=r) printf("%d\n",n);
					else printf("%d\n",max(1,n-2));
				}else if(l>r){
					while(f1[l]&&l>1) --l;
					while(f2[r]&&r<n) ++r;
					if(l<=r) printf("%d\n",n);
					else printf("%d\n",max(1,n-2));
				}else{
					printf("%d\n",n);
				}
				continue;
			}
		}
		
		l=1,r=0;
		while(l<n){
			while(!f1[l]&&l<n) ++l;
			r=l+1;
			while(f1[r]&&r<=n) ++r;
			if(l!=r-1) sort(s1+l,s1+r);
			l=r;
		}
		
		l=1,r=0;
		while(l<n){
			while(!f2[l]&&l<n) ++l;
			r=l+1;
			while(f2[r]&&r<=n) ++r;
			if(l!=r-1) sort(s2+l,s2+r);
			l=r;
		}
		
		int ans=0;
		for(int i=1;i<=n;++i) if(s1[i]==s2[i]) ++ans;
		printf("%d\n",ans);
	}
	return 0;
}
