#include<bits/stdc++.h>
using namespace std;
#define int long long
inline int read(){
	int s=0,f=0;
	char cha;
	cha=getchar();
	while(!isdigit(cha)){
		f|=(cha=='-');
		cha=getchar();
	}
	while(isdigit(cha)){
		s=(s<<1)+(s<<3)+(cha^48);
		cha=getchar();
	}
	return f?-s:s;
}
const int maxn=1e5+10;
int dp[maxn][3][3];
int n;
char s1[maxn],s2[maxn];
char t1[maxn],t2[maxn];
bool fl1[maxn],fl2[maxn];
bool now1,now2;
int ans[maxn];
int cnt[4][4];
int pre1[maxn],pre2[maxn];
bool flag1,flag2,flag3; 
int cnt1,cnt2;
bool ch1,ch2;
void solve1(){
	int res=0;
	for (int i=1;i<=n;i++){
		if (s1[i]==s2[i]) res++;
	}
	printf("%lld\n",res);
}
void solve2(){
	int res1=0,res2=0;
	int res=0;
	int len=0;
	for (int i=1;i<=n;i++){
		if (t1[i]=='0'){
			res+=len-abs(res1-res2);
			len=res1=res2=0;
			res+=(s1[i]==s2[i]);
		}
		else{
			if (s1[i]=='1') res1++;
			if (s2[i]=='1') res2++;
			len++;
		}
	}
	res+=len-abs(res1-res2);
	printf("%lld\n",res);
}
bool check1(int x,int st){
	if (x==st) return 1;
	if (x>st) swap(x,st);
	return ((pre1[st]-pre1[x-1])==(st-x+1));
}
bool check2(int x,int st){
	if (x==st) return 1;
	if (x>st) swap(x,st);
	return ((pre2[st]-pre2[x-1])==(st-x+1));
}
void solve3(){
	bool flag=0;
	int sp1,sp2;
	for (int i=1;i<=n;i++){
		pre1[i]=pre1[i-1]+(t1[i]=='1');
		pre2[i]=pre2[i-1]+(t2[i]=='1');
		if (s1[i]=='0') sp1=i;
		if (s2[i]=='0') sp2=i;
	}
	for (int i=1;i<=n;i++){
		if (check1(i,sp1)&&check2(i,sp2)) flag=1;
	}
	if (flag) printf("%lld\n",n);
	else printf("%lld\n",n-2);
}
void solve(){
	flag1=flag2=flag3=1;
	cnt1=cnt2=0;
	int res=0;
	n=read();
	scanf("%s",s1+1);
	scanf("%s",s2+1);
	scanf("%s",t1+1);
	scanf("%s",t2+1);
	for (int i=1;i<=n;i++){
		fl1[i]=(t1[i]=='1');
		fl2[i]=(t2[i]=='1');
	}
	for (int i=1;i<n;i++){
		if (s1[i]!=s1[i+1]) flag1=0;
	}
	for (int i=1;i<=n;i++){
		if (t1[i]!=t2[i]) flag2=0;
	}
	for (int i=1;i<=n;i++){
		if (s1[i]=='0') cnt1++;
		if (s2[i]=='0') cnt2++;
	}
	if (cnt1!=1||cnt2!=1) flag3=0;
	if (flag1){
		solve1();//
		return;
	}
	if (flag2){
		solve2();//
		return;
	}
	if (flag3){//
		solve3();//
		return;
	}
	memset(cnt,0,sizeof(cnt));
	//return;
	//ch1=ch2=0;
	for (int i=1;i<=n;i++){
		now1=s1[i]-'0';
		now2=s2[i]-'0';
		if (now1==now2){
			res++;
		}
		else{
			cnt[1][now1]++,cnt[2][now2]++;
			if (cnt[1][1-now1]&&fl1[i]&&cnt[2][0]&&cnt[2][1])
			{
				cnt[1][1-now1]--,cnt[1][now1]--;
				cnt[2][1-now2]--,cnt[2][now2]--;
				res+=2;
			}
			else if(cnt[2][1-now2]&&fl2[i]&&cnt[1][0]&&cnt[1][1]){
				cnt[2][1-now2]--,cnt[2][now2]--;
				cnt[1][1-now1]--,cnt[1][now1]--;
				res+=2;
			}
			if (!fl1[i]){
				cnt[1][0]=cnt[1][1]=0;
			}
			if (!fl2[i]){
				cnt[2][0]=cnt[2][1]=0;
			}
		}
		//cout<<cnt[1][0]<<" "<<cnt[1][1]<<" "<<cnt[2][0]<<" "<<cnt[2][1]<<endl;
	}
	cout<<res<<endl;
	return;
}
signed main(){
	freopen("edit.in","r",stdin);//
	freopen("edit.out","w",stdout);//
	int T=read();
	while(T--){
		solve();
	}
	return 0;
} 

//
/*
1
6
011101
111010
111010
101101
*/
