#include <bits/stdc++.h>
using namespace std;
int T;
int n;
int a[100005] ,b[100005];
int f[100005] ,f2[100005];
int lst_a[100005] ,lst_b[100005];
int cnta[100005][2] ,cntb[100005][2];
int pos[200005] ,cur;
int main(){
	freopen("edit.in" ,"r" ,stdin);
	freopen("edit.out" ,"w" ,stdout);
	cin.tie(0) ,cout.tie(0) ,ios::sync_with_stdio(false);
	cin >> T;
	while(T--){
		memset(cnta ,0 ,sizeof(cnta));
		memset(cntb ,0 ,sizeof(cntb));
		cur=0;
		cin >> n;
		for(int i=1;i<=n;i++){
			char c;cin >> c;
			a[i]=c-'0';
		}
		for(int i=1;i<=n;i++){
			char c;cin >> c;
			b[i]=c-'0';
		}
		for(int i=1;i<=n;i++){
			char c;cin >> c;
			f[i]=c-'0';
		}
		for(int i=1;i<=n;i++){
			char c;cin >> c;
			f2[i]=c-'0';
		}
//		if(T!=3)continue;
		int lst=1;
		for(int i=1;i<=n;i++){
			if(i==1||!f[i]||!f[i-1])
				lst=i;
			if(lst==i)
				pos[++cur]=i;
			lst_a[i]=lst;
			cnta[lst][a[i]]++;
		}
		lst=1;
		for(int i=1;i<=n;i++){
			if(i==1||!f2[i]||!f2[i-1])
				lst=i;
			if(lst==i)
				pos[++cur]=i;
			lst_b[i]=lst;
			cntb[lst][b[i]]++;
		}
//		cout << "debug : \n";
//		for(int i=1;i<=n;i++)
//			cout << f[i];
//		cout << endl;
		sort(pos+1 ,pos+cur+1);
		int ans=0 ,cur2=0;
		for(int i=1;i<=cur;i++)
			if(i==1||pos[i]!=pos[cur2])
				pos[++cur2]=pos[i];
		pos[++cur2]=n+1;
		cur=cur2-1;
		for(int i=1;i<=cur;i++){
			int id=pos[i] ,len=pos[i+1]-pos[i];
			int a0=cnta[lst_a[id]][0] ,a1=cnta[lst_a[id]][1];
			int b0=cntb[lst_b[id]][0] ,b1=cntb[lst_b[id]][1];
			ans+=min(len ,min(a0 ,b0)+min(a1 ,b1));
			int del0=min(len ,min(a0 ,b0));
			int del1=min(max(0 ,len-min(a0 ,b0)) ,min(a1 ,b1));
//			cout << id << " : " << a0 << ' ' << a1 << ' ' << b0 << ' ' << b1 << endl;
//			cout << lst_a[id] << ' ' << lst_b[id] << endl;
			cnta[lst_a[id]][0]-=del0;
			cntb[lst_b[id]][0]-=del0;
			cnta[lst_a[id]][1]-=del1;
			cntb[lst_b[id]][1]-=del1;
		}
//		cout << endl;
		cout << ans << endl;
	}
}
