#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int T;
int n;
#define N 100005
string s1,s2,t1,t2;
int sum1[N],sum2[N];
void input() {
scanf ("%d",&n);
cin >> s1>>s2>>t1>>t2;
}
void init() {
memset(sum1,0,sizeof(sum1));
memset(sum2,0,sizeof(sum2));
for(int i=0; i<n; i++)
sum1[i+1]=sum1[i]+(s1[i]-'0');
for(int i=0; i<n; i++)
sum2[i+1]=sum2[i]+(s2[i]-'0');
}
void B() {
int u=0,un[N]= {},ans=0;
for(int i=0; i<n; i++)
if(t1[i]=='0') {
u++,un[u]=i+1;
if(s1[i]==s2[i])ans++;
}
u++;
un[u]=n+1;
for(int i=1; i<=u; i++) {
if(un[i]==un[i-1]+1)continue;
ans+=un[i]-un[i-1]-1-(abs(sum2[un[i]-1]-sum2[un[i-1]]-sum1[un[i]-1]+sum1[un[i-1]]));
}
printf("%d\n",ans);
}
void C() {
int l1=0,l2=0,ans=0;
for(int i=0; i<n; i++) {
if(t1[i]=='0')
l1=i+1;
if(t2[i]=='0')
l2=i+1;
}
int f0=0,ff0=0,s0=0,ss0=0;
int f1=0,ff1=0,s1=0,ss1=0;
f0=l1-1-(sum1[l1-1]);
ff0=l2-1-sum2[l2-1];
s0=n-(sum1[n]-sum2[l1]);
ss0=n-(sum2[n]-sum2[l2]);
f1=sum1[l1-1];
ff1=sum2[l2-1];
s1=sum1[n]-sum2[l1];
ss1=sum2[n]-sum2[l2];
ans+=min(f0,ff0);
ans+=min(f1,ff1);
ans+=min(max(0,ss1-min(f1,ff1)),max(0,ss0-min(f0,ff0)));
ans+=min(max(0,s1-min(f1,ff1)),max(0,s0-min(f0,ff0)));
printf("%d\n",ans);
}
void solve() {
int u=0,u2=0,un[N]= {},un2[N]= {},ans=0;
for(int i=0; i<n; i++)
if(t1[i]=='0') {
u++,un[u]=i+1;
}
u++;
un[u]=n+1;
for(int i=0; i<n; i++)
if(t2[i]=='0') {
u2++,un2[u]=i+1;
}
for(int i=1; i<=u; i++) {
for(int j=1; j<=u2; j++) {
if(un[i]<=un2[j]) {
int f0=0,ff0=0,s0=0,ss0=0;
int f1=0,ff1=0,s1=0,ss1=0;
int l1=un[i],l2=un2[j];
f0=-1-(sum1[l1-1]);
ff0=l2-1-sum2[l2-1];
s0=n-(sum1[n]-sum2[l1]);
ss0=n-(sum2[n]-sum2[l2]);
f1=sum1[l1-1];
ff1=sum2[l2-1];
s1=sum1[n]-sum2[l1];
ss1=sum2[n]-sum2[l2];
ans+=min(f0,ff0);
ans+=min(f1,ff1);
ans+=min(max(0,ss1-min(f1,ff1)),max(0,ss0-min(f0,ff0)));
ans+=min(max(0,s1-min(f1,ff1)),max(0,s0-min(f0,ff0)));
break;
}
}
}
printf("%d\n",ans);
}
void A(int a) {
if(a==0) {
printf("%d\n",sum2[n]);
} else {
printf("%d\n",n-sum2[n]);
}
}
int main() {
freopen("edit.in","r",stdin);
freopen("edit.out","w",stdout);
scanf ("%d",&T);
while(T--) {
int zero1=0,zero2=0;
input();
init();
if(t1==t2) {
B();
continue;
}
int flag1=0,flag0=0;
for(int i=1; i<=n; i++) {
if(s1[i]=='0')flag0=1;
else if(s1[i]=='1')flag1=1;
}
if((flag1==1&&flag0==0 )|| (flag1==0&&flag0==1)) {
A(flag0);
continue;
}
for(int i=1; i<=n; i++)
if(t1[i]=='0')
zero1++;
else if(t2[i]=='0')
zero2++;
if(zero1==1 && zero2==1) {
C();
continue;
}
solve();
}
return 0;
}