#include<bits/stdc++.h>

using namespace std;

const int N = 1e5 + 10;

char a[N],b[N];
bool vis1[N],vis2[N];
int to[N],n,T;
struct node{
	int x,y;
}d[N];
bool g[N];
void sub1(){
	bool fl=true;int ans=0,sum1=0,sum2=0;
	for(int i=1;i<=n;i++){
		if(a[i]=='0')  fl=false;
	}
	for(int i=1;i<=n;i++){
		if(vis2[i]){
			ans+=(a[i]==b[i]);
			if(fl)  ans+=sum1;
			else ans+=sum2;
			sum1=sum2=0;
			continue;
		}  
		if(b[i]=='1')  sum1++;
		else sum2++;
	}
	cout<<ans<<endl;
}
void sub2(){
	int ans=0;int p1=0,p2=0,s1=0,s2=0;
	for(int i=1;i<=n;i++){
		if((vis1[i]==vis2[i]&&vis1[i])||i==n){
			ans+=(a[i]==b[i]);
			//cout<<p1<<" "<<s1<<" "<<p2<<" "<<s2<<endl;
			ans+=min(p1,s1)+min(p2,s2);
			p1=s1=p2=s2=0;
			continue;
		}
		if(a[i]=='1')  p1++;
		else p2++;
		if(b[i]=='1')  s1++;
		else s2++;  
	}
	cout<<ans<<endl;
}
void sub3(){
	int sum1,sum2,ans=0;
	sum1=sum2=0;
	for(int i=1;i<=n;i++){
	    if(a[i]=='1')  sum1++;
		else sum2++;
		if(vis1[i]){
			//cout<<sum1<<" "<<sum2<<endl;
			int p1=0,p2=0,s1=0,s2=0;
			for(int j=i;j>=1;j--){
				if(vis1[j]&&j!=i){
					//cout<<j<<" "<<i<<endl;
					break;
				}  
				if(vis2[j]){
					if(b[j]=='1')  p1++;
					else p2++;continue;
				}
				int t=to[j];//cout<<t<<" "<<j<<" "<<" "<<d[t].x<<" "<<d[t].y<<endl;
				if(d[t].x&&sum1){
					if(d[t].x>=sum1){
						ans+=sum1;d[t].x-=sum1;sum1=0;
					}
					else{
						ans+=d[t].x;sum1-=d[t].x;d[t].x=0;
					}
				}
				if(d[t].y&&sum2){
					if(d[t].y>=sum2){
						ans+=sum2;d[t].y-=sum2;sum2=0;
					}
					else{
						ans+=d[t].y;sum2-=d[t].y;d[t].y=0;
					}
				}
			}
			//cout<<ans<<" "<<sum1<<" "<<sum2<<" "<<p1<<" "<<p2<<endl;
			ans+=min(sum1,p1);ans+=min(sum2,p2);
			sum1=sum2=0;
			continue;
		}
	}
	cout<<ans<<endl;
}
void solve(){
	memset(d,0,sizeof d);
	memset(vis1,false,sizeof vis1);memset(vis2,false,sizeof vis2);
	cin>>n;int ans=0;bool fs1=true,fs2=true,fs3=true;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		if(a[i]!=a[i-1]&&i>1)  fs1=false;
	} 
	for(int i=1;i<=n;i++)  cin>>b[i];
	int cnt=1,sum1=0,sum2=0;
	for(int i=1,x;i<=n;i++){
		char c;cin>>c;
		if(c=='0'){
			vis1[i]=true;
		}  
	}
	for(int i=1;i<=n;i++){
		char c;cin>>c;to[i]=cnt;
		if(c=='0'){
			//cout<<cnt<<" "<<sum1<<" "<<sum2<<endl;
			d[cnt++]={sum1,sum2};sum1=sum2=0; 
			vis2[i]=true;
			continue;
		} 
		if(b[i]=='1')  sum1++;
		else sum2++;
	}
	if(sum1||sum2)  d[cnt]={sum1,sum2};
	if(fs1)  sub1();
	else if(fs2){
		sub2();
	}  
	else sub3();
}
int main(){
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	cin>>T;
	while(T--)  solve();
	return 0;
}
