#include<bits/stdc++.h>
using namespace std;
const int MAXN=1e5+5;
char s[MAXN],t[MAXN],os[MAXN],ot[MAXN];
int n,is[MAXN],it[MAXN];
struct info {
	int c0,c1;
}	qs[MAXN],qt[MAXN];
void solve() {
	cin>>n>>(s+1)>>(t+1)>>(os+1)>>(ot+1);
	int ks=0,kt=0;
	for(int i=1,j;i<=n;i=j) {
		if(os[i]=='0') j=i+1;
		else for(j=i;j<=n&&os[j]=='1';++j);
		++ks;
		for(int k=i;k<j;++k) ++(s[k]=='1'?qs[ks].c1:qs[ks].c0),is[k]=ks;
	}
	for(int i=1,j;i<=n;i=j) {
		if(ot[i]=='0') j=i+1;
		else for(j=i;j<=n&&ot[j]=='1';++j);
		++kt;
		for(int k=i;k<j;++k) ++(t[k]=='1'?qt[kt].c1:qt[kt].c0),it[k]=kt;
	}
	is[n+1]=ks+1,it[n+1]=kt+1;
	int ans=0;
	info ws=qs[is[1]],wt=qt[it[1]];
	for(int i=1,j;i<=n;i=j) {
		for(j=i;j<=n&&is[j]==is[i]&&it[j]==it[i];++j);
		int u0=min(ws.c0,wt.c0),u1=min(ws.c1,wt.c1),len=j-i;
		if(u0>len) u0=len,u1=0;
		else if(u0+u1>len) u1=len-u0;
		ws.c0-=u0,wt.c0-=u0,ws.c1-=u1,wt.c1-=u1;
		ans+=u0+u1;
		if(is[j]!=is[i]) ws=qs[is[j]];
		if(it[j]!=it[i]) wt=qt[it[j]];
	}
	cout<<ans<<"\n";
	for(int i=1;i<=n+1;++i) is[i]=it[i]=0;
	for(int i=1;i<=ks;++i) qs[i]={0,0};
	for(int i=1;i<=kt;++i) qt[i]={0,0};
}
signed main() {
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	ios::sync_with_stdio(false);
	int T; cin>>T;
	while(T--) solve();
	return 0;
}
