#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll T,n;
char x[100010],y[100010];
char s[100010],t[100010];
bool check1(){
	bool l=false,y=false;
	for(ll i=1;i<=n;i++){
		if(x[i]=='0') l=true;
		else y=true;
		if(l&&y) return false;
	}
	return true;
}
void solve1(){
	ll sum=0;
	for(ll i=1;i<=n;i++){
		if(y[i]==x[1]) sum++;
	}
	printf("%lld\n",sum);
}
bool check2(){
	for(ll i=1;i<=n;i++){
		if(s[i]!=t[i]) return false;
	}
	return true;
}
void solve2(){
	ll ans=0;
	ll suml=0,sumy=0,sumel=0,sumey=0;
	for(ll i=1;i<=n;i++){
		if(s[i]=='0'){
			ans+=(x[i]==y[i]);
			ans+=min(suml,sumel)+min(sumy,sumey);
			suml=0,sumy=0,sumel=0,sumey=0;
			continue;
		}
		if(x[i]=='0') suml++;
		if(x[i]=='1') sumy++;
		if(y[i]=='0') sumel++;
		if(y[i]=='1') sumey++; 
	}
	ans+=min(suml,sumel)+min(sumy,sumey);
	printf("%lld\n",ans);
}
bool check3(){
	ll l=false,y=false;
	for(ll i=1;i<=n;i++){
		if(s[i]=='0'){
			if(l) return false;
			l=true;
		}
		if(t[i]=='0'){
			if(y) return false;
			y=true;
		}
	}
	return true;
}
void solve3(){
	ll preyl=0,preyy=0,nxtyl=0,nxtyy=0;
	ll preel=0,preey=0,nxtel=0,nxtey=0;
	ll posy=0,pose=0;
	for(ll i=1;i<=n;i++){
		if(s[i]=='0'){
			posy=i;
			continue;
		}
		if(!posy){
			if(x[i]=='0') preyl++;
			else preyy++;
		}
		else{
			if(x[i]=='0') nxtyl++;
			else nxtyy++;
		}
	}
	for(ll i=1;i<=n;i++){
		if(t[i]=='0'){
			pose=i;
			continue;
		}
		if(!pose){
			if(y[i]=='0') preel++;
			else preey++;
		}
		else{
			if(y[i]=='0') nxtel++;
			else nxtey++;
		}
	}
	ll ans=0;
	if(posy>pose){
		swap(posy,pose);
		swap(preyl,preel);
		swap(preyy,preey);
		swap(nxtyl,nxtel);
		swap(nxtyy,nxtey);
		swap(x,y);
	}
	if(x[posy]=='0'){
		if(preel) preel--,ans++;
		else preey--;
	}
	else{
		if(preey) preey--,ans++;
		else preel--;
	}
	if(y[pose]=='0'){
		if(nxtyl) nxtyl--,ans++;
		else nxtyy--;
	}
	else{
		if(nxtyy) nxtyy--,ans++;
		else nxtyl--;
	}
	ans+=min(preey,preyy+nxtyy)+min(preel,preyl+nxtyl);
	ll rest=preel+preey-preyl-preyy;
	if(preel>=preyl){
		preel-=preyl;
		if(nxtyl>=preel) nxtyl-=preel,rest=0;
		else nxtyl=0,rest-=nxtyl;
	}
	if(preey>=preyy){
		preey-=preyy;
		if(nxtyy>=preey) nxtyy-=preey;
		else nxtyy=0;
	}
	ans+=min(nxtyl,nxtel)+min(nxtyy,nxtey);
	printf("%lld\n",ans);
}
ll all=0;
ll cal(){
	ll res=0;
	for(ll i=1;i<=n;i++){
		if(x[i]==y[i]) res++;
	}
	return res;
}
map<string,bool> vis,vs;
void solve(){
	all=max(all,cal());
	if(vis[x]&&vis[y]) return;
	vis[x]=true;
	vis[y]=true;
	for(ll i=1;i<n;i++){
		if(x[i]=='0'||x[i+1]=='0') continue;
		for(ll j=1;j<n;j++){
			if(y[i]=='0'||y[i+1]=='0') continue;
			swap(x[i],x[i+1]);
			swap(y[j],y[j+1]);
			solve();
			swap(x[i],x[i+1]);
			swap(y[j],y[j+1]);
		}
	}
}
void solve4(){
	all=0;
	solve();
	printf("%lld\n",all);
}
void solve5(){
	cout<<rand()%n+1<<endl;
}
int main(){
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	scanf("%lld",&T);
	while(T--){
		scanf("%lld",&n);
		scanf("%s%s%s%s",x+1,y+1,s+1,t+1);
		if(n<=10) solve4();
		else if(check1()) solve1();
		else if(check2()) solve2();
		else if(check3()) solve3();
		else solve5();
	}
	return 0;
}
