#include<bits/stdc++.h>
#define Pair pair<int,int>
using namespace std;
const int MAXN=1e5+5;
int n;
int s[MAXN],t[MAXN];
int S[MAXN][2],T[MAXN][2];
inline int sum1(int l,int r,int k){return S[r][k]-S[l-1][k];}
inline int sum2(int l,int r,int k){return T[r][k]-T[l-1][k];}
int can1[MAXN],can2[MAXN];
struct DSU{
	int fa[MAXN],L[MAXN],R[MAXN];
	int find(int x){return x==fa[x]?x:fa[x]=find(fa[x]);}
	inline void merge(int x,int y){fa[find(x)]=find(y);}
	inline void clear(){
		for(int i=1;i<=n;i++)fa[i]=i,L[i]=n+1,R[i]=0;
	}
	inline void init(){
		for(int i=1;i<=n;i++){
			L[find(i)]=min(L[find(i)],i);
			R[find(i)]=max(R[find(i)],i);
		}
	}
}T1,T2;
int cnt1[MAXN][2],cnt2[MAXN][2];
inline void solve(){
	memset(cnt1,0,sizeof cnt1);
	memset(cnt2,0,sizeof cnt2);
	memset(can1,0,sizeof can1);
	memset(can2,0,sizeof can2);
	memset(S,0,sizeof S),memset(T,0,sizeof T);
	memset(s,0,sizeof s),memset(t,0,sizeof t);
	cin>>n;
	for(int i=1;i<=n;i++){
		char x;cin>>x;s[i]=x-'0';
		S[i][0]=S[i-1][0];
		S[i][1]=S[i-1][1];
		S[i][s[i]]++;
	}
	for(int i=1;i<=n;i++){
		char x;cin>>x;t[i]=x-'0';
		T[i][0]=T[i-1][0];
		T[i][1]=T[i-1][1];
		T[i][t[i]]++;
	}
	for(int i=1;i<=n;i++){
		char x;cin>>x;can1[i]=x-'0';
	}
	for(int i=1;i<=n;i++){
		char x;cin>>x;can2[i]=x-'0';
	}
	T1.clear(),T2.clear();
	for(int i=1;i<n;i++)if(can1[i]&&can1[i+1])T1.merge(i,i+1);
	for(int i=1;i<n;i++)if(can2[i]&&can2[i+1])T2.merge(i,i+1);
	T1.init(),T2.init();
	for(int i=1;i<=n;i++)if(T1.find(i)==i){
		int l1=T1.L[T1.find(i)],r1=T1.R[T1.find(i)];
		cnt1[l1][0]=sum1(l1,r1,0);
		cnt1[l1][1]=sum1(l1,r1,1);
	}
	for(int i=1;i<=n;i++)if(T2.find(i)==i){
		int l2=T2.L[T2.find(i)],r2=T2.R[T2.find(i)];
		cnt2[l2][0]=sum2(l2,r2,0);
		cnt2[l2][1]=sum2(l2,r2,1);
	}
	int ans=0;
	for(int i=1;i<=n;i++){
		int l1=T1.L[T1.find(i)],r1=T1.R[T1.find(i)];
		int l2=T2.L[T2.find(i)],r2=T2.R[T2.find(i)];
		int mn0=min(cnt1[l1][0],cnt2[l2][0]);
		int mn1=min(cnt1[l1][1],cnt2[l2][1]);
		if(mn0==0&&mn1==0){
			if(cnt1[l1][0]){
				cnt1[l1][0]--;
				cnt2[l2][1]--;
			}else{
				cnt1[l1][1]--;
				cnt2[l2][0]--;
			}
			continue;
		}
		ans++;
		if(mn0>=mn1){
			cnt1[l1][0]--;
			cnt2[l2][0]--;
		}else{
			cnt1[l1][1]--;
			cnt2[l2][1]--;
		}
	}
	cout<<ans<<"\n";
}
#define Fopen(file) freopen(file".in","r",stdin),freopen(file".out","w",stdout)
signed main(){
	Fopen("edit");
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(false);
	int T;cin>>T;while(T--)solve();
} 

/*
1
6
111111
001110
101100
010011

1
6
011101
111010
111010
101101

我是曼巴，我要发表退役演讲：

“曼巴出局！” 

*/
