#include<bits/stdc++.h>
#define ll long long
#define endl '\n'
using namespace std;
const int N=2e5+10;
int f[N],s[2][N],T,n,ans;
char a1[N],a2[N],b1[N],b2[N];
int find(int x){return x==f[x]?x:f[x]=find(f[x]);}
void merge(int u,int v){
	u=find(u),v=find(v);
	if(u==v)return;
	f[u]=v;
	s[0][v]+=s[0][u],s[1][v]+=s[1][u];
}
void calc(int u,int v){
	for(int i=0;i<=1;i++){
		int k=min(s[i][u],s[i][v]);
		s[i][u]-=k,s[i][v]-=k;
		ans+=k;
	}
	int k=min(s[0][u]+s[1][u],s[0][v]+s[1][v]);
	int x=k;
	for(int i=0;i<=1;i++){
		int k=min(x,s[i][v]);
		x-=k,s[i][v]-=k;
	}
	x=k;
	for(int i=0;i<=1;i++){
		int k=min(x,s[i][u]);
		x-=k,s[i][u]-=k;
	}
}
void solve(){
	cin>>n>>(a1+1)>>(a2+1)>>(b1+1)>>(b2+1);
	for(int i=1;i<=n*2;i++)f[i]=i,s[0][i]=s[1][i]=0;
	for(int i=1;i<=n;i++)s[a1[i]-'0'][i]++,s[a2[i]-'0'][i+n]++;
	for(int i=1;i<n;i++){
		if(b1[i]=='1'&&b1[i+1]=='1')merge(i,i+1);
		if(b2[i]=='1'&&b2[i+1]=='1')merge(i+n,i+n+1);
	}
	ans=0;
	for(int i=1;i<=n;i++)if(b1[i]=='0'||b2[i]=='0')calc(find(i),find(i+n));
	for(int i=1;i<=n;i++)calc(find(i),find(i+n));
	cout<<ans<<endl;
}
signed main(){
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	int T;cin>>T;
	while(T--)solve();
}

