#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+5;
ll ans;
int sum1[5],sum2[5],a1[maxn],a2[maxn],l1[maxn],l2[maxn],T,n,Sum1[5],Sum2[5];
string st1,st2,t1,t2;
void uad(){
if(sum1[0]>=sum2[0]) sum1[0]-=sum2[0],sum2[0]=0;
else sum2[0]-=sum1[0],sum1[0]=0;
if(sum1[1]>=sum2[1]) sum1[1]-=sum2[1],sum2[1]=0;
else sum2[1]-=sum1[1],sum1[1]=0;
}
int main(){
freopen("edit2.in","r",stdin);
freopen("edit2.out","w",stdout);
cin>>T;
for(int i=1;i<=T;i++){
cin>>n;
cin>>st1;
cin>>st2;
cin>>t1;
cin>>t2;
ans=0;
sum1[1]=0,sum1[0]=0,sum2[0]=0,sum2[1]=0,Sum1[1]=0,Sum1[0]=0,Sum2[0]=0,Sum2[1]=0;
for(int j=0;j<n;j++){
a1[j+1]=st1[j]-'0';
a2[j+1]=st2[j]-'0';
l1[j+1]=t1[j]-'0';
l2[j+1]=t2[j]-'0';
}
for(int j=1;j<=n;j++){
if(l1[j]==0&&l2[j]!=0){
ans+=min(sum1[0],sum2[0])+min(sum1[1],sum2[1]);
uad();
sum2[0]=max(0,sum2[0]-Sum2[0]),sum2[1]=max(0,sum2[1]-Sum2[0]);
Sum2[0]=0,Sum2[1]=0;
if(a2[j]==0) sum2[0]++;
else sum2[1]++;
if(a1[j]==0) sum1[0]++;
else sum1[1]++;
Sum1[0]+=sum1[0],Sum1[1]+=sum1[1];
}
if(l2[j]==0&&l1[j]!=0){
ans+=min(sum1[0],sum2[0])+min(sum1[1],sum2[1]);
uad();
sum1[0]=max(0,sum1[0]-Sum1[0]),sum1[1]=max(0,sum1[1]-Sum1[0]);
Sum1[0]=0,Sum1[1]=0;
if(a1[j]==0) sum1[0]++;
else sum1[1]++;
if(a2[j]==0) sum2[0]++;
else sum2[1]++;
Sum2[0]+=sum2[0],Sum2[1]+=sum2[1];
}
if(l2[j]==0&&l1[j]==0){
ans+=min(sum1[0],sum2[0])+min(sum1[1],sum2[1]);
if(a1[j]==a2[j]) ans++;
sum1[0]=0,sum1[1]=0,sum2[0]=0,sum2[1]=0,Sum1[1]=0,Sum1[0]=0,Sum2[1]=0,Sum2[0]=0;
}
if(l1[j]!=0&&l2[j]!=0){
if(a1[j]==0) sum1[0]++;
else sum1[1]++;
if(a2[j]==0) sum2[0]++;
else sum2[1]++;
}
}
ans+=min(sum1[0],sum2[0])+min(sum1[1],sum2[1]);
cout<<ans<<endl;
}
return 0;
}