#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+6;
int T,n,cnt1,cnt2,ans;
int b[maxn],c1[maxn][2],c2[maxn][2],bin[2][maxn],u1[maxn],u2[maxn];
char s1[maxn],s2[maxn],t1[maxn],t2[maxn];
void dfs(int x){
if(x==n+1){
int res=0;
for(int i=1;i<=n;i++)
if(u1[i]==u2[i])
res++;
ans=max(ans,res);
return ;
}
u1[x]=0,u2[x]=0,dfs(x+1);
u1[x]=1,u2[x]=0,dfs(x+1);
u1[x]=0,u2[x]=1,dfs(x+1);
u1[x]=1,u2[x]=1,dfs(x+1);
}
int main(){
freopen("edit.in","r",stdin);
freopen("edit.out","w",stdout);
scanf("%d",&T);
while(T--){
memset(b,0,sizeof b),cnt1=cnt2=1,ans=0;
scanf("%d%s%s%s%s",&n,s1+1,s2+1,t1+1,t2+1);
if(n<=10){
for(int i=1;i<=n;i++)
if(t1[i]=='0'){
b[i]++,bin[0][i]=cnt1;
if(i!=n)
cnt1++;
}
else c1[cnt1][s1[i]-'0']++,bin[0][i]=cnt1;
for(int i=1;i<=n;i++)
if(t2[i]=='0'){
b[i]++,bin[1][i]=cnt2;
if(i!=n)
cnt2++;
}
else c2[cnt2][s2[i]-'0']++,bin[1][i]=cnt2;
dfs(1);
printf("%d\n",n/2+1);
}
else{
ans=0;
for(int i=1;i<=n;i++)
if(s1[i]==s2[i])
ans++;
printf("%d\n",ans);
}
}
return 0;
}