#include<bits/stdc++.h>
using namespace std;
const int N=1e6+86;
int n,t;
string t1,t2;
struct T{
	int c=0;
	int l=0;
};
T a[N],b[N];
struct K{
	int a1,b0;
};
K suma[N],sumb[N];
int aed[N],bed[N];
char ch;
void fna(){
	int ans=0;
	int aa=0;
	int ca=a[1].c;
	for(int i=1;i<=n;i++){
		if(b[i].c==ca) ans++;
	}
	cout<<ans<<endl;
}
void fnb(){
	int ans=0;
	int aa=0,ab=0,ba=0,bb=0;
	for(int i=1;i<=n;i++){
		if(t1[i-1]!='0'){
			if(a[i].c==1) aa++;
			else ab++;
			if(b[i].c==1) ba++;
			else bb++;
		}
		else{
			if(a[i].c==b[i].c){
				ans++;
			}
			ans+=min(aa,ba)+min(ab,bb);
			aa=ab=bb=ba=0;
		}
	}
	cout<<ans<<endl;
}
void fnc(int eda,int edb){
//	cout<<"s"<<endl;
	int maxa=0,maxb=0,mina=0,minb=0;
	int ans=0;
	for(int i=1;i<=n;i++) {
		suma[i].a1=suma[i].b0=0;
		sumb[i].a1=sumb[i].b0=0;
	}
	for(int i=1;i<=n;i++){
		if(a[i].c==1) {
			suma[i].a1=suma[i-1].a1+1;
			suma[i].b0=suma[i-1].b0;
		}else{
			suma[i].a1=suma[i-1].a1;
			suma[i].b0=suma[i-1].b0+1;
		} 
		if(b[i].c==1) {
			sumb[i].a1=sumb[i-1].a1+1;
			sumb[i].b0=sumb[i-1].b0;
		}else{
			sumb[i].a1=sumb[i-1].a1;
			sumb[i].b0=sumb[i-1].b0+1;
		} 
	}
	if(eda<edb){
		sumb[n].a1=sumb[n].a1-sumb[edb].a1;
		sumb[n].b0=sumb[n].b0-sumb[edb].b0;
		mina=min(suma[eda].a1,sumb[edb-1].a1);
		minb=min(suma[eda].b0,sumb[edb-1].b0);
		ans=ans+mina+minb;
		suma[n].a1-=suma[eda].a1;
		suma[n].b0-=suma[eda].b0;
		mina=min(suma[n].a1,sumb[edb].a1-mina);
		minb=min(suma[n].b0,sumb[edb].b0-minb);
		ans+=mina+minb;
		suma[n].a1-=mina;
		suma[n].b0-=minb;
		mina=min(suma[n].a1,sumb[n].a1);
		minb=min(suma[n].b0,sumb[n].b0);
		ans+=mina+minb;
		printf("%d\n",ans);
	}else{
		suma[n].a1=suma[n].a1-suma[edb].a1;
		suma[n].b0=suma[n].b0-suma[edb].b0;
		mina=min(sumb[edb].a1,suma[eda-1].a1);
		minb=min(sumb[edb].b0,suma[eda-1].b0);
		ans=ans+mina+minb;
		sumb[n].a1-=sumb[edb].a1;
		sumb[n].b0-=sumb[edb].b0;
		mina=min(sumb[n].a1,suma[eda].a1-mina);
		minb=min(sumb[n].b0,suma[eda].b0-minb);
		ans+=mina+minb;
		sumb[n].a1-=mina;
		sumb[n].b0-=minb;
		mina=min(suma[n].a1,sumb[n].a1);
		minb=min(suma[n].b0,sumb[n].b0);
		ans+=mina+minb;
		cout<<ans<<endl;
	}
}
void inti(int nn){
	int at=0,bt=0;
	char cc=' ',eda=0,edb=0;
	bool ll=0;
	for(int i=1;i<=nn;i++){
		a[i].c=0;
		a[i].l=0;
	}
	for(int i=1;i<=nn;i++){
		cin>>ch;
		if(cc==' ') cc=ch;
		else if(cc!=' '){
			if(cc!=ch) ll=1;
		}
		a[i].c=ch-'0';
	}
	for(int i=1;i<=nn;i++){
		cin>>ch;
		b[i].c=ch-'0';
	}
	getchar();
	getline(cin,t1);
	getline(cin,t2);
	for(int i=0;i<n;i++){
		if(t1[i]=='0'){
			at++;
			eda=i+1;
		}
		if(t2[i]=='0'){
			bt++;
			edb=i+1;
		}
	}
	if(ll==0){
		fna();
	}else if(t1==t2){
		fnb();
	}else if(at==1&&bt==1){
		fnc(eda,edb);
	}
}
int main(){
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	scanf("%d",&t);
	while(t--){
		scanf("%d",&n);
		inti(n);
	}
	return 0;
}
