#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
int nxt1[N],nxt2[N],T,n,ans;
char s1[N],s2[N],t1[N],t2[N];
bool A,B,C;
void init(){
	nxt1[n]=nxt2[n]=n;
	for(int i=n-1;i>=1;i--){
		if(t1[i+1]&&t1[i]) nxt1[i]=nxt1[i+1];
		else nxt1[i]=i;
		if(t2[i+1]&&t2[i]) nxt2[i]=nxt2[i+1];
		else nxt2[i]=i;
	}
}
void dfs2(int u){
	if(u==n+1){
		int res=0;
		for(int i=1;i<=n;i++){
			if(s1[i]==s2[i]) res++;
		}
		ans=max(ans,res);return;
	}
	do{
		dfs2(nxt2[u]+1);
	}while(next_permutation(s2+u,s2+nxt2[u]+1));
}
void dfs1(int u){
	if(u==n+1){dfs2(1);return;}
	do{
		dfs1(nxt1[u]+1);
	}while(next_permutation(s1+u,s1+nxt1[u]+1));
}
void baoli(){
	init();
	for(int i=1;i<=n;i++){
		sort(s1+i,s1+nxt1[i]+1);
		i=nxt1[i];
	}
	for(int i=1;i<=n;i++){
		sort(s2+i,s2+nxt2[i]+1);
		i=nxt2[i];
	}
	dfs1(1);
	printf("%d\n",ans);
}
void solveA(){
	for(int i=1;i<=n;i++){
		if(s1[i]==s2[i]) ans++;
	}
	printf("%d\n",ans);
}
void solveB(){
	init();int len=0,sum1=0,sum2=0;
	for(int i=1;i<=n;i++){
		sum1+=(s1[i]=='1'),sum2+=(s2[i]=='1'),len++;
		if(nxt1[i]==i){
			ans+=min(sum1,sum2)+min(len-sum1,len-sum2);
			sum1=sum2=len=0;
		}
	}
	printf("%d\n",ans);
}
int calc(int l,int r,int id){
	int res=0;
	for(int i=l;i<=r;i++){
		if(id==1) res+=(s1[i]=='1');
		else res+=(s2[i]=='1');
	}
	return res;
}
void solveC(){
	int p1=0,p2=0;
	for(int i=1;i<=n;i++){
		if(!t1[i]) p1=i;
		if(!t2[i]) p2=i;
	}
	if(p1>p2) swap(p1,p2),swap(s1,s2);
	int l1=1,r1=p1-1,l2=p1+1,r2=n;
	int l3=1,r3=p2-1,l4=p2+1,r4=n;
	int sum1=calc(l1,r1,1),sum2=calc(l2,r2,1),sum3=calc(l3,r3,2),sum4=calc(l4,r4,2);
	int sum11=r1-l1+1-sum1,sum33=r3-l3+1-sum3,sum22=r2-l2+1-sum2,sum44=r4-l4+1-sum4;
	if(l1<=r1){
		int num1=min(sum1,sum3),num2=min(sum11,sum33);
		ans+=num1+num2,sum3-=num1,sum33-=num2;
	}
	if(l4<=r4){
		int num1=min(sum4,sum2),num2=min(sum22,sum44);
		ans+=num1+num2,sum2-=num1,sum22-=num2;
	}
	int maxn=0;
	if(ans) ans-=2;
	for(int i=0;i<2;i++){
		int ex=0;
		if(i){
			if(!sum3) continue;
			sum3--;
			if(s1[p1]=='1') ex=1;
		}
		else{
			if(!sum33) continue;
			sum33--;
			if(s1[p1]=='0') ex=1;
		}
		for(int j=0;j<2;j++){
			int exx=0;
			if(j){
				if(!sum2) continue;
				sum2--;
				if(s2[p2]=='1') exx=1;
			}
			else{
				if(!sum22) continue;
				sum22--;
				if(s2[p2]=='0') exx=1;
			}
			maxn=max(maxn,min(sum2,sum3)+min(sum22,sum33)+ex+exx);
			if(j) sum2++;
			else sum22++;
		}
		if(i) sum3++;
		else sum33++;
	}
	ans+=maxn;
	printf("%d\n",ans);
}
void solve(){printf("Yeah,I like furry!!!\n");}
void furry(){
	scanf("%d%s%s%s%s",&n,s1+1,s2+1,t1+1,t2+1);
	int sum1=0,sum2=0;ans=0;
	A=B=true,C=false;
	for(int i=1;i<=n;i++){
		if(i>1&&s1[i]!=s1[i-1]) A=false;
		if(t1[i]!=t2[i]) B=false;
		t1[i]-='0',t2[i]-='0',sum1+=(!t1[i]),sum2+=(!t2[i]);
	}
	if(sum1==1&&sum2==1) C=true;
	if(n<=10) baoli();
	else if(A) solveA();
	else if(B) solveB();
	else if(C) solveC();
	else solve();
}
int main(){
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	scanf("%d",&T);
	while(T--) furry();
	fclose(stdin);fclose(stdout);
	return 0;
} 
