#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=4e5+5; 

int T;
int n;
char c[N],d[N];
int a[N],b[N];
char t1[N],t2[N];

int sum1[N],sum2[N]; // ÐòÁÐ1 
int sum3[N],sum4[N]; // ÐòÁÐ2 

int tot;
struct qwq{
	int l,r,i;
}ee[N],e[N];
bool cmp(const qwq &x,const qwq &y){
	if(x.l==y.l) return x.r>y.r;
	return x.l<y.l;
}

void INit(){
	scanf("%s%s",t1+1,t2+1);
	t1[n+1]=t2[n+1]='0';
	int lst=0, nw=0;
	for(int i=1;i<=n;i++){
		if(t1[i]=='1'){
			if(!nw) lst=i;
			nw++;
		}
		if(nw && t1[i+1]=='0'){
			ee[++tot].l=lst; ee[tot].r=i; 
			ee[tot].i=1;
			nw=0;	
		}
	}
	lst=nw=0;
	for(int i=1;i<=n;i++){
		if(t2[i]=='1'){
			if(!nw) lst=i;
			nw++;
		}
		if(nw && t2[i+1]=='0'){
			ee[++tot].l=lst; ee[tot].r=i; 
			ee[tot].i=2;
			nw=0;	
		}
	}	
}

bool bk1[N],bk2[N];

void Solve(){
	for(int i=1;i<=n;i++){
		sum1[i]=sum2[i]=0; sum3[i]=sum4[i]=0;
		bk1[i]=bk2[i]=0;
	}
	tot=0;
	scanf("%d%s%s",&n,c+1,d+1);
	int ans1=0; //
	for(int i=1;i<=n;i++){
		a[i]=c[i]-'0'; b[i]=d[i]-'0';
		if(a[i]==b[i]) ans1++;
		sum1[i]=sum1[i-1]; sum2[i]=sum2[i-1]; sum3[i]=sum3[i-1]; sum4[i]=sum4[i-1];
		if(a[i]==0) sum1[i]++; else sum2[i]++;
		if(b[i]==0) sum3[i]++; else sum4[i]++;
	}
//	cout<<ans1<<" "<<sum1[n]<<" "<<sum2[n]<<" "<<sum3[n]<<" "<<sum4[n]<<"\n";
	
	INit();
	sort(ee+1,ee+tot+1,cmp);
	int cnt=0;
	
	e[0].l=e[0].r=0;
	for(int i=1;i<=tot;i++){
//		cout<<ee[i].i<<" "<<ee[i].l<<" "<<ee[i].r<<"\n";
		if(ee[i].r<=e[cnt].r) continue;
		e[++cnt]=ee[i];
//		cout<<e[cnt].i<<" "<<e[cnt].l<<" "<<e[cnt].r<<"\n";
	}
	e[cnt+1].l=n+1; e[cnt+1].r=n+1;
//	cout<<"\n";
	
	int zans=0;
	int lres0=0, lres1=0;
	for(int i=1;i<=cnt;i++){
		int nwl=e[i].l, nwr=e[i].r;
		for(int j=e[i].l;j<=e[i].r;j++){
			if(e[i].i==1) bk1[j]=1;
			else bk2[j]=1;
		}
		if(e[i-1].r>=e[i].l) nwl=e[i-1].r+1;
		if(e[i+1].l<=e[i].r) nwr=e[i+1].l-1;
		
		int nw0, nw1, rnw0, rnw1;
		if(e[i].i==1){
			nw0=sum1[e[i].r]-sum1[e[i].l-1];
			nw1=sum2[e[i].r]-sum2[e[i].l-1];
			rnw0=sum3[nwr]-sum3[nwl-1];
			rnw1=sum4[nwr]-sum4[nwl-1];				
		}
		else{
			nw0=sum3[e[i].r]-sum3[e[i].l-1];
			nw1=sum4[e[i].r]-sum4[e[i].l-1];
			rnw0=sum1[nwr]-sum1[nwl-1];
			rnw1=sum2[nwr]-sum2[nwl-1];				
		}	
//		cout<<e[i].i<<" "<<e[i].l<<" "<<e[i].r<<"\n";
//		cout<<nwl<<" "<<nwr<<"    "<<nw0<<" "<<nw1<<" "<<rnw0<<" "<<rnw1<<"\n";	
		int res0=min(nw0,rnw0), res1=min(nw1,rnw1);
		zans+=res0+res1;
		
		int resa=nw0-res0, resb=nw1-res1;
		if(e[i-1].r>=e[i].l){
			int nr0=min(lres0,resa), nr1=min(lres1,resb);
			int nlen=e[i-1].r-e[i].l+1;
			if(nr0+nr1>nlen){
				if(nlen-nr0>=0) nr1=nlen-nr0;
				else if(nlen-nr1>=0) nr0=nlen-nr1;
				else nr0=0,nr1=nlen;
			}
			zans+=nr0+nr1;
			resa-=nr0; resb-=nr1;
		}
		if(e[i+1].l<=e[i].r){
			lres0=resa; lres1=resb;
		}
		else{
			lres0=0; lres1=0;
		}
	}
	
	for(int i=1;i<=n;i++)
		if(!bk1[i] && !bk2[i] && a[i]==b[i])
			zans++;
	
	printf("%d\n",zans);
}

int main(){
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	
	scanf("%d",&T);
	while(T--){
		Solve(); 
	}
	return 0;
}

