#include <bits/stdc++.h>

using namespace std;
const int N=1e5+5;
int n,tmp[N],tmpp[N],cnt[3][N],cntt[3][N],ct,ctt,ans,pre;
char s[5][N];
void work(){
	cin>>n;ans=0;ct=1;pre=0;
	memset(cnt,0,sizeof(cnt));
	memset(cntt,0,sizeof(cntt));
	for (int i=1;i<=4;i++){
		for (int j=1;j<=n;j++) cin>>s[i][j];
	}
	for (int i=1;i<=n;i++){
		tmp[i]=ct;
		if (s[3][i]=='0') ct++;
		else cnt[s[1][i]-'0'][ct]++;
	}
	for (int i=1;i<=n;i++){
		tmpp[i]=ctt;
		if (s[4][i]=='0') ctt++;
		else cntt[s[2][i]-'0'][ctt]++;
	}
	for (int i=1;i<=n;i++){
		if (s[3][i]=='0'&&s[4][i]=='0'){
			int a=min(min(cnt[0][tmp[i]],cntt[0][tmpp[i]]),i-pre-1),b=min(min(cnt[1][tmp[i]],cntt[1][tmpp[i]]),i-pre-1);
			ans+=a+b;
			ans+=(s[1][i]==s[2][i]);
			pre=i;
			continue ;
		} else if (s[3][i]=='0'){
			int a=min(min(cnt[0][tmp[i]],cntt[0][tmpp[i]]),i-pre-1),b=min(min(cnt[1][tmp[i]],cntt[1][tmpp[i]]),i-pre-1);
			ans+=a+b;
			cntt[0][tmpp[i]]-=a;cntt[1][tmpp[i]]-=b;
			if (cntt[s[1][i]-'0'][tmpp[i]]) cntt[s[1][i]-'0'][tmpp[i]]--,ans++;
			pre=i;
			continue ;
		} else if (s[4][i]=='0'){
			int a=min(min(cnt[0][tmp[i]],cntt[0][tmpp[i]]),i-pre-1),b=min(min(cnt[1][tmp[i]],cntt[1][tmpp[i]]),i-pre-1);
			ans+=a+b;
			cnt[0][tmp[i]]-=a;cnt[1][tmp[i]]-=b;
			if (cnt[s[2][i]-'0'][tmp[i]]) cnt[s[2][i]-'0'][tmp[i]]--,ans++;
			pre=i;
			continue ;
		}
	}
	int a=min(min(cnt[0][tmp[n]],cntt[0][tmpp[n]]),n+1-pre-1),b=min(min(cnt[1][tmp[n]],cntt[1][tmpp[n]]),n+1-pre-1);
	ans+=a+b;
	cout<<ans<<endl;
}
signed main(){
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	ios::sync_with_stdio(0);
	int t;cin>>t;while (t--) work();
	return 0;
}
