#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10; 
int n,a[N],b[N],c[N],d[N],ans;
void solve(){
	ans=0;
	cin>>n;
	for(int i=1;i<=n;i++)scanf("%1d",&a[i]);
	for(int i=1;i<=n;i++)scanf("%1d",&b[i]);
	for(int i=1;i<=n;i++)scanf("%1d",&c[i]);
	for(int i=1;i<=n;i++)scanf("%1d",&d[i]);
	int ca1=0,ca0=0,cb1=0,cb0=0;
	for(int i=1,j=1,k=1;k<=n;k++){
		i=max(i,k);
		j=max(j,k);
		if(!c[k]&&!d[k]){
			ca1=ca0=cb1=cb0=0;
			if(a[k]==b[k])ans++;
			i=j=k+1;
		}else if(c[k]&&!d[k]){
			cb1=cb0=0;
			while(i<=n&&c[i]){
				if(a[i])ca1++;
				else ca0++;
				i++;
			}
			if(b[k]){
				if(ca1)ans++,ca1--;
			}else{
				if(ca0)ans++,ca0--;
			}
		}else if(!c[k]&&d[k]){
			ca1=ca0=0;
			while(j<=n&&d[j]){
				if(b[j])cb1++;
				else cb0++;
				j++;
			}
			if(a[k]){
				if(cb1)ans++,cb1--;
			}else{
				if(cb0)ans++,cb0--;
			}
		}else{
			while(i<=n&&c[i]){
				if(a[i])ca1++;
				else ca0++;
				i++;
			}
			while(j<=n&&d[j]){
				if(b[j])cb1++;
				else cb0++;
				j++;
			}
			if(ca0&&cb0){
				ans++;
				ca0--;
				cb0--;
			}else if(ca1&&cb1){
				ans++;
				ca1--;
				cb1--;
			}
		}
	}
	cout<<ans<<"\n";
}
int main(){
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	int T;cin>>T;
	while(T--)solve();
	return 0;
}
