#include<bits/stdc++.h>
using namespace std;
int T,n;
char a[100005],b[100005],c[100005],d[100005];
int f[100005],g[100005],x[100005],y[100005];
struct node{
	int asum;
	int bsum;
	int flag;
	int flagv;
}ax[100005],bx[100005];
int main()
{
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	cin>>T;
	while(T--){
		cin>>n;
		int ans=0;
		memset(a,0,sizeof(a));
		memset(b,0,sizeof(b));
		memset(c,0,sizeof(c));
		memset(d,0,sizeof(d));
		memset(f,0,sizeof(f));
		memset(g,0,sizeof(g));
		memset(x,0,sizeof(x));
		memset(y,0,sizeof(y));
		memset(ax,0,sizeof(ax));
		memset(bx,0,sizeof(bx));
		for(int i=1;i<=n;i++){
			cin>>a[i];
			g[i]=g[i-1];
			f[i]=f[i-1];
			if(a[i]=='1'){
				f[i]=f[i-1]+1;
			}else{
				g[i]=g[i-1]+1;
			}
		//	cout<<f[i]<<" "<<g[i]<<endl;
		}
		for(int i=1;i<=n;i++){
			cin>>b[i];
			x[i]=x[i-1];
			y[i]=y[i-1];
			if(b[i]=='1'){
				x[i]=x[i-1]+1;
			}else{
				y[i]=y[i-1]+1; 
			}
		}
		for(int i=1;i<=n;i++){
			cin>>c[i];
		}
		for(int i=1;i<=n;i++){
			cin>>d[i];
		}
		int k=0,l=0,t=0,tl=0;
		for(int i=1;i<=n;i++){
			if(c[i]=='0'){
				ax[++t].asum=f[i]-f[k]-(f[i]-f[i-1]);
			//	cout<<f[i]<<" "<<f[k]<<endl;
				ax[t].bsum=g[i]-g[k]-(g[i]-g[i-1]);
				ax[t].flag=i;
				ax[t].flagv=a[i]-'0';
				k=i;
			//	cout<<ax[t].asum<<" "<<ax[t].bsum<<endl;
			//	cout<<g[i]<<" "<<g[k]<<" "<<g[i-1]<<endl;
			}
			if(d[i]=='0'){
				bx[++tl].asum=x[i]-x[l]-(x[i]-x[i-1]);
				bx[tl].bsum=y[i]-y[l]-(y[i]-y[i-1]);
				bx[tl].flag=i;
				bx[tl].flagv=b[i]-'0';
				l=i;
			//	cout<<bx[tl].asum<<" "<<bx[tl].bsum<<endl;
			}
		}
		int o=1,p=1;
		while(o<=t&&p<=tl){
		//	cout<<ax[o].flag<<" "<<bx[p].flag<<endl;
			if(ax[o].flag>bx[p].flag){
				if(bx[p].flagv==1){
					bx[p].asum++;
				}else{
					bx[p].bsum++;
				}
				if(ax[o].asum>=bx[p].asum){
					ax[o].asum-=bx[p].asum;
					ans+=bx[p].asum;
				}else{
					ans+=ax[o].asum;
					ax[o].asum=0;
					ax[o].bsum-=(bx[p].asum-ax[o].asum);
					
				}
				if(ax[o].bsum>=bx[p].bsum){
					ax[o].bsum-=bx[p].bsum;
					ans+=bx[p].bsum;
				}else{
					ans+=ax[o].bsum;
					ax[o].bsum=0;
					ax[o].asum-=(bx[p].bsum-ax[o].bsum);
				}
				p++;
			}else if(ax[o].flag<bx[p].flag){
				if(ax[o].flagv==1){
					ax[o].asum++;
				}else{
					ax[o].bsum++;
				}
				if(bx[p].asum>=ax[o].asum){
					bx[p].asum-=ax[o].asum;
					ans+=ax[o].asum;
				}else{
					ans+=bx[p].asum;
					bx[p].asum=0;
					bx[p].bsum-=(ax[o].asum-bx[p].asum);
				}
				if(bx[p].bsum>=ax[o].bsum){
					bx[p].bsum-=ax[o].bsum;
					ans+=ax[o].bsum;
				}else{
					ans+=bx[p].bsum;
					bx[p].bsum=0;
					bx[p].asum-=(ax[o].bsum-bx[p].bsum);
				}
				o++;
			//	cout<<ans<<endl;
			}else{
				if(ax[o].flagv==bx[p].flagv){
					ans++;
				}if(bx[p].asum>=ax[o].asum){
					bx[p].asum-=ax[o].asum;
					ans+=ax[o].asum;
				}else{
					ans+=bx[p].asum;
					bx[p].asum=0;
					bx[p].bsum-=(ax[o].asum-bx[p].asum);
					
				}
				if(bx[p].bsum>=ax[o].bsum){
					bx[p].bsum-=ax[o].bsum;
					ans+=ax[o].bsum;
				}else{
					ans+=bx[p].bsum;
					bx[p].bsum=0;
					bx[p].asum-=(ax[o].bsum-bx[p].bsum);
				}
				o++;
			//	cout<<ans<<endl;
			}
			if(o>t){
				/*for(int j=ax[o-1].flag+1;j<=n;j++){
					if(a[j]=='1'){
						
					}
				}*/
				ans+=min((f[n]-f[ax[o-1].flag]),(bx[p].asum+x[n]-x[bx[p].flag-1]));
				ans+=min((g[n]-g[ax[o-1].flag]),(bx[p].bsum+y[n]-y[bx[p].flag-1]));
			//	cout<<ans<<endl;
			}
			if(p>tl){
				ans+=min((x[n]-x[bx[p-1].flag]),(ax[o].asum+f[n]-f[ax[o].flag-1]));
				ans+=min((y[n]-y[bx[p-1].flag]),(ax[o].bsum+g[n]-g[ax[o].flag-1]));
		//		cout<<ans<<endl;
			//	cout<<x[n]<<" "<<x[bx[p-1].flag]<<" "<<ax[o].asum<<" "<<f[n]<<" "<<f[ax[o].flag-1]<<endl;
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}

