#include<bits/stdc++.h>
using namespace std;
const int N=100005;
int _;
int n;
char s1[N],s2[N],s3[N];
char t1[N],t2[N];
bool flgA,flgB,flgC;
int ans;
int workA(){
	int ret=0;
	for(int i=1;i<=n;i++) ret+=(s1[i]==s2[i]);
	return ret;
}
int workB(){
	int ret=0;
	for(int i=1;i<=n;i++){
		if(t1[i]=='0') {
			ret+=(s1[i]==s2[i]);
			continue;
		}
		int j=i;
		while(j<n&&t1[j+1]=='1') ++j;
		int cnt1=0,cnt2=0;
		for(int k=i;k<=j;k++)
			cnt1+=(s1[k]=='0'),
			cnt2+=(s2[k]=='0');
		ret+=min(cnt1,cnt2);
		cnt1=cnt2=0;
		for(int k=i;k<=j;k++)
			cnt1+=(s1[k]=='1'),
			cnt2+=(s2[k]=='1');
		ret+=min(cnt1,cnt2);
		i=j;
	}
	return ret;
}
int f[N],g[N];
int work0(){
	for(int i=1;i<=n;i++) f[i]=i;
	for(int i=1;i<=n;i++) s3[i]=s2[i];
	int ret=0;
	bool flg; int m;
	do{
		flg=true;
		for(int i=1;i<=n;i++) if(t2[i]=='0'&&f[i]!=i){flg=false; break;}
		if(!flg) continue;
		for(int i=1;i<=n;i++){
			if(t2[i]=='0') continue;
			int j=i;
			while(j<n&&t2[j+1]=='1') ++j;
			m=0;
			for(int k=i;k<=j;k++) g[++m]=f[k];
			sort(g+1,g+m+1);
			if(g[1]!=i||g[m]!=j) {flg=false; break;}
			i=j;
		}
		if(!flg) continue;
		for(int i=1;i<=n;i++) s2[i]=s3[f[i]];
		ret=max(ret,workB());
	}while(next_permutation(f+1,f+n+1));
	return ret;
}
int workD(){
	int ret=0;
	for(int i=1;i<=n;i++){
		if(t1[i]=='0'&&t2[i]=='0') {
			ret+=(s1[i]==s2[i]);
			continue;
		}
		int j=i;
		while(j<n&&(t1[j+1]=='1'||t2[j+1]=='1')) ++j;
		int cnt1=0,cnt2=0;
		for(int k=i;k<=j;k++)
			cnt1+=(s1[k]=='0'),
			cnt2+=(s2[k]=='0');
		ret+=min(cnt1,cnt2);
		cnt1=cnt2=0;
		for(int k=i;k<=j;k++)
			cnt1+=(s1[k]=='1'),
			cnt2+=(s2[k]=='1');
		ret+=min(cnt1,cnt2);
		i=j;
	}
	return ret;
}
void Solve(){
	ans=0;
	scanf("%d",&n);
	scanf("%s",s1+1);
	scanf("%s",s2+1);
	scanf("%s",t1+1);
	scanf("%s",t2+1);
	flgA=flgB=flgC=true;
	for(int i=1;i<n;i++) flgA&=(s1[i]==s1[i+1]);
	for(int i=1;i<=n;i++) flgB&=(t1[i]==t2[i]);
	int cnt=0;
	for(int i=1;i<=n;i++) cnt+=(t1[i]=='0');
	flgC&=(cnt==1); cnt=0;
	for(int i=1;i<=n;i++) cnt+=(t2[i]=='0');
	flgC&=(cnt==1); 
	if(flgA) ans=workA();
	else if(flgB) ans=workB();
	else if(n<=10) ans=work0();
	else ans=workD();
	printf("%d\n",ans);
} 
int main(){
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	scanf("%d",&_);
	while(_--) Solve();
	return 0;
}
/*
1
6
011101
111010
111010
101101
*/
