#include<bits/stdc++.h>
using namespace std;
int T,n,s1[100100],s2[100100],t1[100100],t2[100100],ans,cnt;
int pt1[2],pt2[2];
char ch;
void upd10(){pt1[0]++;while(t1[pt1[0]]&&s1[pt1[0]]) pt1[0]++;}
void upd11(){pt1[1]++;while(t1[pt1[1]]&&(!s1[pt1[1]])) pt1[1]++;}
void upd20(){pt2[0]++;while(t2[pt2[0]]&&s2[pt2[0]]) pt2[0]++;}
void upd21(){pt2[1]++;while(t2[pt2[1]]&&(!s2[pt2[1]])) pt2[1]++;}
void check(int my1,int my2){
bool f=1;
if(my1>=pt1[0]) upd10();
else if(my1>=pt1[1]) upd11();
else if(my2>=pt2[0]) upd20();
else if(my2>=pt2[1]) upd21();
else if(s1[pt1[0]]) upd10();
else if(!s1[pt1[1]]) upd11();
else if(s2[pt2[0]]) upd20();
else if(!s2[pt2[1]]) upd21();
else f=0;
if(f) check(my1,my2);
}
int main(){
freopen("edit.in","r",stdin);
freopen("edit.out","w",stdout);
cin>>T;
while(T--){
ans=cnt=0;
memset(t1,0,sizeof(t1));
memset(t2,0,sizeof(t2));
memset(s1,0,sizeof(s1));
memset(s2,0,sizeof(s2));
pt1[0]=pt1[1]=pt2[0]=pt2[1]=0;
cin>>n;
bool A0=1,A1=1,B=1,C0=0;
for(int i=1;i<=n;i++){cin>>ch;s1[i]=ch-'0';if(s1[i]) A0=0;else A1=0;}
for(int i=1;i<=n;i++){cin>>ch;s2[i]=ch-'0';}
for(int i=1;i<=n;i++){cin>>ch;t1[i]=ch-'0';}
for(int i=1;i<=n;i++){cin>>ch;t2[i]=ch-'0';if(t1[i]!=t2[i]) B=0;}
int cnt1=0,cnt2=0,cnt3=0;
for(int i=1;i<=n;i++) if(!t1[i]) cnt1++;
for(int i=1;i<=n;i++) if(!t2[i]) cnt2++;
if(cnt1+cnt2==0) C0=1;
if(A0||A1){
for(int i=1;i<=n;i++) if(s1[i]==s2[i]) ans++;
cout<<ans<<'\n';
continue;
}
if(B||C0){
cnt1=cnt2=cnt3=0;
for(int i=1;i<=n;i++){
if(t1[i]==0&&t2[i]==0){
ans+=(cnt3-max(cnt1,cnt2)+min(cnt1,cnt2));
cnt1=cnt2=cnt3=0;
if(s1[i]==s2[i]) ans++;
}else{
if(s1[i]) cnt1++;
if(s2[i]) cnt2++;
cnt3++;
}
}
ans+=(cnt3-max(cnt1,cnt2)+min(cnt1,cnt2));
cout<<ans<<'\n';
continue;
}
for(int i=1;i<=n;i++){
check(i-1,i-1);
s1[n+1]=s2[n+1]=2;
if(s1[i]==s2[i]){
ans++;
continue;
}
if(!(t1[i]||t2[i])) continue;
if(!t1[i]){
int f_d=pt2[s1[i]];
if(!t2[f_d]) continue;
swap(s2[i],s2[f_d]);
ans++;
continue;
}
if(!t2[i]){
int f_d=pt1[s2[i]];
if(!t1[f_d]) continue;
swap(s1[i],s1[f_d]);
ans++;
continue;
}
int fd10=pt1[0],fd11=pt1[1],fd20=pt2[0],fd21=pt2[1];
if(t1[fd10]&&t2[fd20]){
swap(s1[i],s1[fd10]);
swap(s2[i],s2[fd20]);
ans++;
continue;
}
if(t1[fd11]&&t2[fd21]){
swap(s1[i],s1[fd11]);
swap(s2[i],s2[fd21]);
ans++;
continue;
}
}
cout<<ans<<'\n';
}
return 0;
}