#include<bits/stdc++.h>
#define pc __builtin_popcountll
using namespace std;
typedef long long ll;
const int N=1e5+3;
int T,n,m1,m2,sum1[N],sum2[N];
char s1[N],s2[N],a1[N],a2[N];
bool flag1,flag2,flag3,abl1[N],abl2[N];
struct node{
	int l,r,sum;
}q1[N],q2[N];
bool ck1(int i){
	for(int j=1,l,r,sum;j<=m1;j++){
		l=q1[j].l,r=q1[j].r,sum=0;for(int k=l;k<=r;k++) sum+=((i>>k-1)&1);
		if(sum!=q1[j].sum) return 0;
	}
	for(int j=1;j<=n;j++) if(a1[j]=='0' && ((i>>j-1)&1)!=(s1[j]-'0')) return 0;
	return 1;
}
bool ck2(int i){
	for(int j=1,l,r,sum;j<=m2;j++){
		l=q2[j].l,r=q2[j].r,sum=0;for(int k=l;k<=r;k++) sum+=((i>>k-1)&1);
		if(sum!=q2[j].sum) return 0;
	}
	for(int j=1;j<=n;j++) if(a2[j]=='0' && ((i>>j-1)&1)!=(s2[j]-'0')) return 0;
	return 1;
}
int c1[3][2],c2[3][2];
int main(){
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	scanf("%d",&T);
	while(T--){
		scanf("%d%s%s%s%s",&n,s1+1,s2+1,a1+1,a2+1);
		int ans=0;flag1=flag2=flag3=1;
		for(int i=1;i<=n;i++){
			flag1&=(s1[1]==s1[i]);
			flag2&=(a1[i]==a2[i]);
			sum1[i]=sum1[i-1]+(s1[i]-'0');
			sum2[i]=sum2[i-1]+(s2[i]-'0');
		}
		m1=0,m2=0;
		for(int l=1,r=1,sum;l<=n;){
			while(r<=n && a1[l]==a1[r]) r++;r--;
			sum=0;for(int i=l;i<=r;i++) sum+=s1[i]-'0';
			q1[++m1]=node{l,r,sum};
			l=r+1,r=l;
		}
		for(int l=1,r=1,sum;l<=n;){
			while(r<=n && a2[l]==a2[r]) r++;r--;
			sum=0;for(int i=l;i<=r;i++) sum+=s2[i]-'0';
			q2[++m2]=node{l,r,sum};
			l=r+1,r=l;
		}
		if(n<=10){
			for(int i=0;i<(1<<n);i++) abl1[i]=ck1(i),abl2[i]=ck2(i);
			for(int i=0;i<(1<<n);i++) for(int j=0;j<(1<<n);j++) if(abl1[i] && abl2[j]) ans=max(ans,n-pc(i^j));
		}else if(flag1){
			for(int i=1;i<=n;i++) ans+=(s1[i]==s2[i]);
		}else if(flag2){
			assert(m1==m2);
			for(int i=1,l,r,tp;i<=m1;i++){
				l=q1[i].l,r=q1[i].r,tp=a1[l]-'0';
				if(tp){
					ans+=min(q1[i].sum,q2[i].sum)+min((r-l+1)-q1[i].sum,(r-l+1)-q2[i].sum);
				}else{
					for(int j=l;j<=r;j++) ans+=(s1[j]==s2[j]);
				}
			}
		}else{
			puts("I love this shujushanchu wisdom T1 problem maker.");
			puts("Which shujushanchu shujushanchu human makes this shujushanchu T1?");
			puts("shujushanchu NOIP");
			puts("AFO!!!");
		}
		printf("%d\n",ans);
	}
	return 0;
}

