#include<algorithm> 
#include<iostream> 
#include<cstdio> 
#include<string> 
#include<math.h> 
#include<map>
//#define int long long
using namespace std;
const int N=2e5+10;
const int M=1e5+10;
int n;
string s1,s2,t1,t2;
bool checkA(){
	for(int i=1;i<n;i++){
		if(s1[i]!=s1[0])return 0;
	}
	return 1;
}
void solveA(){
	int ans=0;
	for(int i=0;i<n;i++){
		if(s1[i]==s2[i])ans++;
	}
	cout<<ans<<'\n';
	return ;
}
bool checkB(){
	for(int i=0;i<n;i++){
		if(t1[i]!=t2[i])return 0;
	}
	return 1;
}
void solveB(){
	int ans=0;
	int suma[2],sumb[2];
	suma[0]=sumb[0]=suma[1]=sumb[1]=0;
	for(int i=0;i<n;i++){
		if(t1[i]=='1'){
			suma[s1[i]-'0']++;
			sumb[s2[i]-'0']++;
		}else{
			
			suma[0]=sumb[0]=suma[1]=sumb[1]=0;
			if(s1[i]==s2[i])ans++;
		}
	}
	ans+=min(suma[0],sumb[0]);
	ans+=min(suma[1],sumb[1]);
	cout<<ans<<'\n';
	return ;
}
int sum0[N],sum1[N],l[N],r[N],ida,idb,sum00[N],sum11[N];
void initt(){
	ida=idb=0;
	int ll=-1,rr=-1,summ0=0,summ1=0;
	for(int i=0;i<n;i++){
		if(t1[i]=='1'){
			if(ll==-1){
				ll=i;
				summ0=summ1=0;
			}
			if(s1[i]=='0')summ0++;
			if(s1[i]=='1')summ1++;
			rr=i;
		}else{
			if(ll!=-1){
				ida++;
				sum0[ida]=summ0;
				sum1[ida]=summ1;
				l[ida]=ll;
				r[ida]=rr;
				ll=rr=-1;
				summ0=summ1=0;
			}
			if(ll==-1){
				ll=i;
				summ0=summ1=0;
			}
			if(s1[i]=='0')summ0++;
			if(s1[i]=='1')summ1++;
			rr=i;
			if(ll!=-1){
				ida++;
				sum0[ida]=summ0;
				sum1[ida]=summ1;
				l[ida]=ll;
				r[ida]=rr;
				ll=rr=-1;
				summ0=summ1=0;
			}
		}
	}	
	if(ll!=-1){
		ida++;
		sum0[ida]=summ0;
		sum1[ida]=summ1;
		l[ida]=ll;
		r[ida]=rr;
		ll=rr=-1;
		summ0=summ1=0;
	}
			
	ll=rr=-1,summ0=0,summ1=0;
	for(int i=0;i<n;i++){
		if(t2[i]=='1'){
			if(ll==-1){
				ll=i;
				summ0=summ1=0;
			}
			if(s2[i]=='0')summ0++;
			if(s2[i]=='1')summ1++;
			rr=i;
		}else{
			if(ll!=-1){
				idb++;
				sum0[idb+n]=summ0;
				sum1[idb+n]=summ1;
				l[idb+n]=ll;
				r[idb+n]=rr;
				ll=rr=-1;
				summ0=summ1=0;
			}
			if(ll==-1){
				ll=i;
				summ0=summ1=0;
			}
			if(s2[i]=='0')summ0++;
			if(s2[i]=='1')summ1++;
			rr=i;
			if(ll!=-1){
				idb++;
				sum0[idb+n]=summ0;
				sum1[idb+n]=summ1;
				l[idb+n]=ll;
				r[idb+n]=rr;
				ll=rr=-1;
				summ0=summ1=0;
			}
		}
	}
	if(ll!=-1){
		idb++;
		sum0[idb+n]=summ0;
		sum1[idb+n]=summ1;
		l[idb+n]=ll;
		r[idb+n]=rr;
		ll=rr=-1;
		summ0=summ1=0;
	}
	return ;
} 
void SOLVE(){
	cin>>n;
	cin>>s1>>s2>>t1>>t2;
	if(checkA()){
		solveA();
		return ;
	}
	if(checkB()){
		solveB();
		return ;
	}
	initt();
	
	/*for(int i=1;i<=ida;i++){
		printf("l:%d r:%d sum0:%d sum1:%d\n",l[i],r[i],sum0[i],sum1[i]);
	}
	cout<<"\n";
	for(int i=1;i<=idb;i++){
		printf("l:%d r:%d sum0:%d sum1:%d\n",l[i+n],r[i+n],sum0[i+n],sum1[i+n]);
	}
	cout<<"\n";*/
	
	int ans=0,j=1,i=1;
	while(i<=ida&&j<=idb){
		sum00[i]=sum0[i];
		sum11[i]=sum1[i];
		sum00[j+n]=sum0[j+n];
		sum11[j+n]=sum1[j+n];
		int min0=min(sum0[i],sum0[n+j]);
		int min1=min(sum1[i],sum1[n+j]);
		sum0[i]-=min0;
		sum0[n+j]-=min0;
		sum1[i]-=min1;
		sum1[n+j]-=min1;
		int lenn;
		if(r[i]<=r[j+n]){
			lenn=r[i]-l[j+n]+1;
		}else{
			lenn=r[j+n]-l[i]+1;
		}
		ans+=min(lenn,min0+min1);
		
		//printf("l1:%d r1:%d l2:%d r2:%d sum:%d",l[i],r[i],l[j+n],r[j+n],);
		
		if(r[i]<=r[j+n]){
			i++;
		}else{
			j++;
		}
	}
	
	/*
	for(int i=1;i<=ida;i++){
		printf("l:%d r:%d sum00:%d sum11:%d\n",l[i],r[i],sum00[i],sum11[i]);
	}
	cout<<"\n";
	for(int i=1;i<=idb;i++){
		printf("l:%d r:%d sum00:%d sum11:%d\n",l[i+n],r[i+n],sum00[i+n],sum11[i+n]);
	}
	cout<<"\n";
	*/
	
	int ans2=0;
	j=idb,i=ida;
	while(i>0&&j>0){
		int min00=min(sum00[i],sum00[n+j]);
		int min11=min(sum1[i],sum11[n+j]);
		sum00[i]-=min00;
		sum00[n+j]-=min00;
		sum11[i]-=min11;
		sum11[n+j]-=min11;
		int lenn;
		if(l[i]<=l[j+n]){
			lenn=r[i]-l[j+n]+1;
		}else{
			lenn=r[j+n]-l[i]+1;
		}
		ans2+=min(lenn,min00+min11);
		
		//printf("l1:%d r1:%d l2:%d r2:%d sum:%d",l[i],r[i],l[j+n],r[j+n],);
		
		if(l[i]<=l[j+n]){
			j--;
		}else{
			i--;
		}
	}
	
	cout<<max(ans,ans)<<'\n';

	
	return ;
}
signed main(){
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	int T;
	cin>>T;
	while(T--){
		//cout<<T<<"\n";
		SOLVE();
	}
	return 0;
}
/*
1
10
0110111100
1111111100
1110000100
0110111011

*/
