#include<bits/stdc++.h>
#define int long long
#define f(i,j,k) for(int i=j;i<=k;i++)
#define rf(i,j,k) for(int i=j;i>=k;i--)
#define mm(i) memset(i,0,sizeof i)
#define rm(i) memset(i,0x3f,sizeof i)
using namespace std;
const int N=2e5+10;
const double pi=acos(-1.0);
const int mo=998244353;
int T,n;
string s1,s2,s3,s4;
signed 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--){
cin>>n;
cin>>s1>>s2>>s3>>s4;
bool subtask1=1;
for(int i=1;i<s1.size();i++){
if(s1[i]!=s1[i-1]) subtask1=0;
}
if(subtask1){
int ans=0;
for(int i=0;i<s2.size();i++) if(s2[i]==s1[0]) ans++;
cout<<ans<<"\n";
continue;
}
bool subtask2=1;
if(s3!=s4) subtask2=0;
if(subtask2){
int c1=0,c2=0,c3=0,c4=0;
int ans=0;
for(int i=0;i<s1.size();i++){
if(s3[i]=='1'){
if(s1[i]=='1') c1++;
else c2++;
if(s2[i]=='1') c3++;
else c4++;
}
else{
ans+=min(c1,c3)+min(c2,c4)+(s1[i]==s2[i]);
c1=c2=c3=c4=0;
}
}
ans+=min(c1,c3)+min(c2,c4);
cout<<ans<<"\n";
continue;
}
bool subtask3=1;
int s00=0,id0=0,s10=0,id1=0;
for(int i=0;i<s3.size();i++){
if(s3[i]=='0') s00++,id0=i;
if(s4[i]=='0') s10++,id1=i;
}
if(s00!=1||s10!=1) subtask3=0;
if(subtask3){
int ans=0;
int c11=0,c10=0,c21=0,c20=0,c31=0,c30=0,c41=0,c40=0;
for(int i=0;i<s3.size();i++){
if(i<id0){
if(s1[i]=='1') c11++;
else c10++;
}
else if(i>id0){
if(s1[i]=='1') c21++;
else c20++;
}
if(i<id1){
if(s2[i]=='1') c31++;
else c30++;
}
else if(i>id1){
if(s2[i]=='1') c41++;
else c40++;
}
}
if(id0>id1){
if(s1[id0]=='1') c21++;
else c20++;
if(s2[id1]=='1') c31++;
else c30++;
ans+=min(c10,c30)+min(c11,c31)+min(c20,c40)+min(c21,c41);
c10=max((int)0,c10-c30),c11=max((int)0,c11-c31);
c40=max((int)0,c40-c20),c41=max((int)0,c41-c21);
ans+=min(c11,c41)+min(c10,c40);
}
else if(id0<id1){
if(s1[id0]=='1') c11++;
else c10++;
if(s2[id1]=='1') c41++;
else c40++;
ans+=min(c20,c40)+min(c21,c41)+min(c10,c30)+min(c11,c31);
c30=max((int)0,c30-c10),c31=max((int)0,c31-c11);
c20=max((int)0,c20-c40),c21=max((int)0,c21-c41);
ans+=min(c31,c21)+min(c30,c20);
}
else{
ans+=min(c10,c30)+min(c11,c31)+min(c21,c41)+min(c20,c40)+(s1[id0]==s2[id1]);
}
cout<<ans<<"\n";
continue;
}
cout<<n/2<<"\n";
}
return 0;
}