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

#define LL long long

void read(LL &x){
	scanf("%lld",&x);
}

void write(LL x,LL op=1){
	if(!op) printf("%lld ",x);
	else printf("%lld\n",x);
}

const LL N=1e5+10;

LL n,suma[2],sumb[2];

char a[N],b[N],bla[N],blb[N];

namespace subtask1{
	const LL M=1<<10;
	bool vis[M];
	LL sa[M<<1],sb[M<<1],cnta,cntb;
	LL ans=0;
	LL calc(LL x){
		LL ans=0;
		while(x){
			if(x&1) ans++;
			x>>=1;
		}
		return ans;
	}
	bool checka(LL x,LL y){
		bool bl=true;
		for(LL i=x;i<=y;i++) bl&=(bla[i]=='1');
		return bl;
	}
	bool checkb(LL x,LL y){
		bool bl=true;
		for(LL i=x;i<=y;i++) bl&=(blb[i]=='1');
		return bl;
	}
	void dfsa(LL s){
		if(vis[s]) return ;
		vis[s]=true;
		sa[++cnta]=s;
		for(LL i=1;i<=n;i++){
			for(LL j=i+1;j<=n;j++){
				if(!checka(i,j)) continue;
				LL nw=s-(1<<(i-1))*(a[i]-'0')-(1<<(j-1))*(a[j]-'0');
				swap(a[i],a[j]);
				nw+=(1<<(i-1))*(a[i]-'0')+(1<<(j-1))*(a[j]-'0');
				dfsa(nw);
				swap(a[i],a[j]);
			}
		}
	}
	void dfsb(LL s){
		if(vis[s]) return ;
		vis[s]=true;
		sb[++cntb]=s;
		for(LL i=1;i<=n;i++){
			for(LL j=i+1;j<=n;j++){
				if(!checkb(i,j)) continue;
				LL nw=s-(1<<(i-1))*(b[i]-'0')-(1<<(j-1))*(b[j]-'0');
				swap(b[i],b[j]);
				nw+=(1<<(i-1))*(b[i]-'0')+(1<<(j-1))*(b[j]-'0');
				dfsb(nw);
				swap(b[i],b[j]);
			}
		}
	}
	void solve(){
		memset(vis,false,sizeof(vis));
		LL s=0,t=0;
		for(LL i=0,j=1;i<n;i++,j*=2) s+=j*(a[i+1]-'0'),t+=j*(b[i+1]-'0');
		cnta=cntb=0;
		dfsa(s);
		memset(vis,false,sizeof(vis));
		dfsb(t);
		ans=0;
		for(LL i=1;i<=cnta;i++) for(LL j=1;j<=cntb;j++) ans=max(ans,n-calc(sa[i]^sb[j]));
		write(ans);
	}
}

bool checkA(){
	for(LL i=2;i<=n;i++) if(a[i]!=a[i-1]) return false;
	return true;
}

bool checkC(){
	LL sum=0,x=-1;
	for(LL i=1;i<=n;i++) sum+=((bla[i]-'0')^1);
	for(LL i=1;i<=n;i++){
		if(bla[i]=='0') x=i;
	}
	if(sum!=1) return false;
	sum=0;
	LL y=-1;
	for(LL i=1;i<=n;i++) sum+=((blb[i]-'0')^1);
	for(LL i=1;i<=n;i++){
		if(blb[i]=='0') y=i;
	}
//	if(sum!=1||x==y) return false;
	if(sum!=1) return false;
	return true;
}

namespace subtask2{
	void solve(){
		LL ans=0;
		for(LL i=1;i<=n;i++) ans+=(a[i]==b[i]);
		write(ans);
	}
}

namespace subtask3{
	void solve(){
//		printf("IN\n");
		LL x=-1;
		for(LL i=1;i<=n;i++){
			if(bla[i]=='0') x=i;
		}
		LL y=-1;
		for(LL i=1;i<=n;i++){
			if(blb[i]=='0') y=i;
		}
		if(x<y){
			swap(x,y);
			for(LL i=1;i<=n;i++) swap(bla[i],blb[i]),swap(a[i],b[i]);
		}
		LL ans=0,suma[2]={0,0},sumb[2]={0,0};
		for(LL i=1;i<=y;i++) suma[a[i]-'0']++,sumb[b[i]-'0']++;
		for(LL i=y+1;i<x;i++) suma[a[i]-'0']++;
		ans+=min(suma[0],sumb[0])+min(suma[1],sumb[1]);
		suma[0]-=min(suma[0],sumb[0]),suma[1]-=min(suma[1],sumb[1]);
		LL sumaa[2]={0,0},sumbb[2]={0,0};
		for(LL i=n;i>=x;i--) sumaa[a[i]-'0']++,sumbb[b[i]-'0']++;
		for(LL i=x-1;i>y;i--) sumbb[b[i]-'0']++;
//		write(n);
//		write(x);
		ans+=min(sumaa[0],sumbb[0])+min(sumaa[1],sumbb[1]);
		sumbb[0]-=min(sumaa[0],sumbb[0]),sumbb[1]-=min(sumaa[1],sumbb[1]);
//		for(LL i=y+1;i<x;i++) suma[a[i]-'0']++,sumbb[b[i]-'0']++;
//		write(suma[0]);
//		write(suma[1]);
//		write(sumbb[0]);
//		write(sumbb[1]);
		ans+=min(x-y-1,min(suma[0],sumbb[0])+min(suma[1],sumbb[1]));
		write(ans);
	}
}

void solve(){
	read(n);
	scanf("%s%s%s%s",a+1,b+1,bla+1,blb+1);
	if(n<=10){
		subtask1::solve();
		return ;
	}
	if(checkA()){
		subtask2::solve();
		return ;
	}
	if(checkC()){
		subtask3::solve();
		return ;
	}
	suma[0]=suma[1]=sumb[0]=sumb[1]=0;
	LL ans=0;
	LL ra=0,rb=0,lsta=0,lstb=0;
	while(ra<n||rb<n){
		if(ra>rb){
			while(rb<ra){
				LL x=rb,sum[2]={0,0};
				x++;
				sum[b[x]-'0']++;
				while(x<n&&blb[x]-'0'&&blb[x+1]-'0') x++,sum[b[x]-'0']++;
				if(x>=ra){
					LL sx=min(suma[0],sumb[0]),sy=min(suma[1],sumb[1]);
					LL summ=sx+sy;
//					ans+=sx+sy;
					suma[0]-=sx,sumb[0]-=sx,suma[1]-=sy,sumb[1]-=sy;
					sx=min(suma[0],sum[0]),sy=min(suma[1],sum[1]);
//					ans+=sx+sy;
					summ+=sx+sy;
					ans+=min(lsta,summ);
					rb=x;
					lstb=rb-ra;
					lsta=0;
					suma[0]=suma[1]=0;
					sumb[0]=sum[0]-sx,sumb[1]=sum[1]-sy;
				}
				else{
					sumb[0]+=sum[0],sumb[1]+=sum[1];
					rb=x;
				}
			}
		}
		else if(ra<rb){
			while(ra<rb){
				LL x=ra,sum[2]={0,0};
				x++;
				sum[a[x]-'0']++;
				while(x<n&&bla[x]-'0'&&bla[x+1]-'0') x++,sum[a[x]-'0']++;
				if(x>=rb){
					LL sx=min(suma[0],sumb[0]),sy=min(suma[1],sumb[1]);
					LL summ=sx+sy;
//					ans+=sx+sy;
					suma[0]-=sx,sumb[0]-=sx,suma[1]-=sy,sumb[1]-=sy;
					sx=min(sumb[0],sum[0]),sy=min(sumb[1],sum[1]);
//					ans+=sx+sy;
					summ+=sx+sy;
					ans+=min(lstb,summ);
					ra=x;
					lsta=ra-rb;
					lstb=0;
					sumb[0]=sumb[1]=0;
					suma[0]=sum[0]-sx,suma[1]=sum[1]-sy;
				}
				else{
					suma[0]+=sum[0],suma[1]+=sum[1];
					ra=x;
				}
			}
		}
		else{
			lsta=0,lstb=0;
			suma[0]=suma[1]=sumb[0]=sumb[1]=0;
			ra++;
			suma[a[ra]-'0']++;
			lsta++;
			while(ra<n&&bla[ra]-'0'&&bla[ra+1]-'0') ra++,suma[a[ra]-'0']++,lsta++;
//			write(lsta);
		}
	}
	write(ans);	
}

int main(){
//	freopen("test.in","r",stdin);
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	LL T=1;
	read(T);
	while(T--){
		solve();
	}
	return 0;
}

