#include <bits/stdc++.h>
#define maxn 100010
using namespace std;
int t;
void solve(){
	int n;scanf("%d",&n);
	char a[maxn],b[maxn],c[maxn],d[maxn];int siga[maxn];memset(siga,0,sizeof siga);
	int sigb[maxn];memset(sigb,0,sizeof sigb);
	int anum0 = 0,bnum0 = 0,anum1 = 0,bnum1 = 0,anum2 = 0,bnum2 = 0,anum3 = 0,bnum3 = 0;
	scanf(" %s",a+1);
	scanf(" %s",b+1);
	scanf(" %s",c+1);
	scanf(" %s",d+1);
	for(int i = 1;i<=n;i++){
		if(siga[i]=='1') siga[i] = siga[i-1]+1;
		if(sigb[i]=='1') sigb[i] = sigb[i-1]+1;
	}
	int ans = 0;
	int lsta = 0,lstb = 0;
	for(int i = 1;i<=n+1;i++){
		if(c[i]=='1'){
			if(a[i]=='0') anum0++;
			if(a[i]=='1') anum1++;
		}
		if(d[i]=='1'){
			if(b[i]=='0') bnum0++;
			if(b[i]=='1') bnum1++;
		}
		if(c[i]=='0' and d[i]=='0'){
			if(c[i]==d[i]) ans++;
			ans+=min(bnum2,anum0);
			anum0-=min(bnum2,anum0);
			ans+=min(bnum3,anum1);
			anum1-=min(bnum3,anum1);
			bnum2 = bnum3 = 0;
			
			ans+=min(anum2,bnum0);
			bnum0-=min(anum2,bnum0);
			ans+=min(anum3,bnum1);
			bnum1-=min(anum3,bnum1);
			anum2 = anum3 = 0;
			
			ans+=min(anum0,bnum0);
			bnum0 = 0;
			anum0 = 0;
			ans+=min(anum1,bnum1);
			bnum1 = 0;
			anum1 = 0;
			lsta = lstb = i;
			continue;
		}
		if(c[i]=='0'){
//			cout<<i<<" "<<anum0<<" "<<anum1<<" "<<bnum0<<" "<<bnum1<<" "<<bnum2<<" "<<bnum3<<endl;
			ans+=min(bnum2,anum0);
			anum0-=min(bnum2,anum0);
			ans+=min(bnum3,anum1);
			anum1-=min(bnum3,anum1);
			bnum2 = bnum3 = 0;
			
			ans+=min((i-siga[i])-(lsta-siga[lsta]),bnum0);
			bnum0-=min((i-siga[i])-(lsta-siga[lsta]),bnum0);
			anum0 = 0;
			ans+=min(siga[i]-siga[lsta],bnum1);
			bnum1-=min(siga[i]-siga[lsta],bnum1);
			anum1 = 0;
			if(a[i-1]=='1') anum3++;
			if(a[i-1]=='0') anum2++;
//			cout<<anum0<<" "<<anum1<<" "<<bnum0<<" "<<bnum1<<" "<<anum2<<" "<<anum3<<endl;
			lsta = i;
		}
		if(d[i]=='0'){
			ans+=min(anum2,bnum0);
			bnum0-=min(anum2,bnum0);
			ans+=min(anum3,bnum1);
			bnum1-=min(anum3,bnum1);
			anum2 = anum3 = 0;
			
			ans+=min(anum0,bnum0);
			anum0-=min(anum0,bnum0);
			bnum0 = 0;
			ans+=min(anum1,bnum1);
			anum1-=min(anum1,bnum1);
			bnum1 = 0;
			if(b[i]=='1') bnum3++;
			if(b[i]=='0') bnum2++;
			lstb = i;
		}
//		if(c[i]=='1' and lsta>lstb){
//			if(a[i]=='0') anum0++;
//			if(a[i]=='1') anum1++;
//		}
//		if(d[i]=='1' and lstb>lsta){
//			if(b[i]=='0') bnum0++;
//			if(b[i]=='1') bnum1++;
//		}
//		cout<<anum0<<" "<<anum1<<" "<<anum2<<" "<<anum3<<endl;
//		cout<<bnum0<<" "<<bnum1<<" "<<bnum2<<" "<<bnum3<<endl;
//		cout<<i<<" "<<ans<<endl;
	}
	printf("%d\n",ans);
}
int main(){
	freopen("edit2.in","r",stdin);
	freopen("edit.out","w",stdout);
	scanf("%d",&t);
	while(t--){
		solve();
	}
	return 0;
}
//一题不会 不适合竞赛属于是！ 
