#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
int read(){
	int res=0,fg=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')fg=-1;c=getchar();}
	while(c>='0'&&c<='9')res=(res<<3)+(res<<1)+c-'0',c=getchar();
	return res*fg;
}
void write(int x){
	if(x<0)putchar('-'),x=-x;
	if(x>9)write(x/10);
	putchar(x%10+'0');
}
const int maxn=2e5+5;
const int mod=998244353;
bool gch(){
	char c=getchar();
	while(c!='0'&&c!='1')c=getchar();
	return c=='1';
}
int n,m;
int a[maxn],b[maxn],c[maxn],d[maxn];
int cnta[maxn][2],cntb[maxn][2],al[maxn],bl[maxn];
void solve(){
	memset(al,0,sizeof al);
	memset(bl,0,sizeof bl);
	memset(cnta,0,sizeof cnta);
	memset(cntb,0,sizeof cntb);
	n=read();
	for(int i=1;i<=n;i++)a[i]=gch();
	for(int i=1;i<=n;i++)b[i]=gch();
	for(int i=1;i<=n;i++)c[i]=gch();
	for(int i=1;i<=n;i++)d[i]=gch();
	for(int i=1;i<=n;i++){
		al[i]=bl[i]=i;
		if(c[i]&&c[i-1])al[i]=al[i-1];
		if(d[i]&&d[i-1])bl[i]=bl[i-1];
		cnta[al[i]][a[i]]++;
		cntb[bl[i]][b[i]]++;
	}
	int ans=0,lst=n+1;
	for(int i=n,j=n;i&&j;){
		ans+=min(min(cnta[al[i]][0],cntb[bl[j]][0]),lst-max(al[i],bl[j]));
		ans+=min(min(cnta[al[i]][1],cntb[bl[j]][1]),lst-max(al[i],bl[j]));
		if(al[i]>bl[j]){
			cntb[bl[j]][0]-=min(min(cnta[al[i]][0],cntb[bl[j]][0]),lst-max(al[i],bl[j]));
			cntb[bl[j]][1]-=min(min(cnta[al[i]][1],cntb[bl[j]][1]),lst-max(al[i],bl[j]));
			i=al[i]-1;
			lst=i+1;
		}else{
			cnta[al[i]][0]-=min(min(cnta[al[i]][0],cntb[bl[j]][0]),lst-max(al[i],bl[j]));
			cnta[al[i]][1]-=min(min(cnta[al[i]][1],cntb[bl[j]][1]),lst-max(al[i],bl[j]));
			if(al[i]==bl[j])i=al[i]-1;
			j=bl[j]-1;
			lst=j+1;
		}
	}
	write(ans),putchar('\n');
}
signed main(){
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	int T=read();
	while(T--)solve();
	return 0;
}
/*
1
6
011101
111010
111010
111101

*/
