#include<bits/stdc++.h>
#define rep(i,a,b)	for(int i = (a);i<=(b);i++)
#define lep(i,a,b)	for(int i = (a);i>=(b);i--)
using namespace std;
const int N = 1e5+10;
int t,n,cnt1,cnt2,cnt3,cnt4,ans,l,r;
char a[N],b[N],c[N],d[N];
inline void solve(){
	cin>>n;
	rep(i,1,n)	cin>>a[i];
	rep(i,1,n)	cin>>b[i];
	rep(i,1,n)	cin>>c[i];
	rep(i,1,n)	cin>>d[i];
	l = n+1,r = n+1;
	cnt1 = cnt2 = cnt3 = cnt4 = ans = 0;
	rep(i,1,n){
		if(c[i] == '0'){
			l = i;
			break;
		}
		if(a[i] == '1')	cnt1++;
		else cnt2++;
	}
	rep(i,1,n){
		if(d[i] == '0'){
			r = i;
			break;
		}
		if(b[i] == '1')	cnt3++;
		else cnt4++;
	}
	while(l<=n || r<=n){
		while(cnt1+cnt2 && cnt3+cnt4){
			if(cnt1 && cnt3)	cnt1--,cnt3--,ans++;
			else if(cnt2 && cnt4)	cnt2--,cnt4--,ans++;
			else{
				if(cnt1 && cnt4)	cnt1--,cnt4--;
				else if(cnt2 && cnt3)	cnt2--,cnt3--;
			}
		}
		if(cnt1+cnt2 == 0 && cnt3+cnt4 == 0){
			if(a[l] == b[r]){
				ans++;
			}
			l++,r++;
			while(l<=n){
				if(c[l] == '0')	break;
				if(a[l] == '1')	cnt1++;
				else cnt2++;
				l++;
			}
			while(r<=n){
				if(d[r] == '0')	break;
				if(b[r] == '1')	cnt3++;
				else cnt4++;
				r++;
			}
		}
		else if(cnt1+cnt2 == 0){
			if(a[l] == '1'){
				if(cnt3){
					cnt3--;
					ans++;
				}
				else cnt4--;
			}
			else{
				if(cnt4){
					cnt4--;
					ans++;
				}
				else	cnt3--;
			}
			l++;
			while(l<=n){
				if(c[l] == '0')	break;
				if(a[l] == '1')	cnt1++;
				else cnt2++;
				l++;
			}
		}
		else{
			if(b[r] == '1'){
				if(cnt1){
					cnt1--;
					ans++;
				}
				else cnt2--;
			}
			else{
				if(cnt2){
					cnt2--;
					ans++;
				}
				else	cnt1--;
			}
			r++;
			while(r<=n){
				if(d[r] == '0')	break;
				if(b[r] == '1')	cnt3++;
				else cnt4++;
				r++;
			}
		}
	}
	ans+=min(cnt1,cnt3)+min(cnt2,cnt4);
	cout<<ans<<"\n";
}
int main(){
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(0);	cout.tie(0);
	cin>>t;
	while(t--)	solve(); 
	return 0;
}	
