#include<bits/stdc++.h>
using namespace std;
#define rep(x,l,r) for(int x=(l);x<=(r);x++)
#define per(x,l,r) for(int x=(r);x>=(l);x--)
#define pc(x) putchar(x)
#define gc() getchar()
#define ll long long
#define ms(x,y) memset(x,y,sizeof(x))
#define msz(x) memset(x,0,sizeof(x))
#define msu(x) memset(x,0x3f,sizeof(x))
#define msl(x) memset(x,0xcf,sizeof(x))
#define fi first
#define se second
const int inf=0x3f3f3f3f;
const ll infll=0x3f3f3f3f3f3f3f3f;
ll read(){
ll x=0,f=1;char c=gc();
while(!isdigit(c)){if(c=='-')f=-1;c=gc();}
while(isdigit(c)){x=10*x+c-'0';c=gc();}
return x*f;
}
template<class A,class B> void ckmax(A &x,B y){x=(x<y)?y:x;}
template<class A,class B> void ckmin(A &x,B y){x=(x>y)?y:x;}
string s1,s2,t1,t2;
pair<int,int> a[100100],b[100100];
int t,n;
int main(){
freopen("edit.in","r",stdin);
freopen("edit.out","w",stdout);
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin>>t;
while(t--){
cin>>n;
cin>>s1>>s2>>t1>>t2;
int z=0,oe=0,pre=1;
s1=" "+s1;s2=" "+s2;
t1=" "+t1;t2=" "+t2;
rep(i,0,n)a[i]={0,0},b[i]={0,0};
rep(i,1,n){
if(t1[i]=='0'){
a[pre]={z,oe};
pre=i+1;
z=0;oe=0;
}else{
if(s1[i]=='0')z++;
else oe++;
}
}a[pre]={z,oe};
z=0;oe=0;pre=1;
rep(i,1,n){
if(t2[i]=='0'){
b[pre]={z,oe};
pre=i+1;
z=0;oe=0;
}else{
if(s2[i]=='0')z++;
else oe++;
}
}b[pre]={z,oe};
int ans=0;
rep(i,1,n){
if(t1[i]=='1'&&t2[i]=='1'){
if(a[i].fi>0&&b[i].fi>0){
a[i].fi--;b[i].fi--;
ans++;
}else if(a[i].se>0&&b[i].se>0){
a[i].se--;b[i].se--;
ans++;
}else{
if(a[i].fi>0&&b[i].se>0)a[i].fi--,b[i].se--;
else if(a[i].se>0&&b[i].fi>0)a[i].se--,b[i].fi--;
}
if(t1[i+1]=='1')a[i+1]=a[i];
if(t2[i+1]=='1')b[i+1]=b[i];
}else if(t1[i]=='1'&&t2[i]=='0'){
if(s2[i]=='0'){
if(a[i].fi>0)a[i].fi--,ans++;
else a[i].se--;
}else{
if(a[i].se>0)a[i].se--,ans++;
else a[i].fi--;
}
if(t1[i+1]=='1')a[i+1]=a[i];
}else if(t1[i]=='0'&&t2[i]=='1'){
if(s1[i]=='0'){
if(b[i].fi>0)b[i].fi--,ans++;
else b[i].se--;
}else{
if(b[i].se>0)b[i].se--,ans++;
else b[i].fi--;
}
if(t2[i+1]=='1')b[i+1]=b[i];
}else if(t1[i]=='0'&&t2[i]=='0'){
if(s1[i]==s2[i])ans++;
}
}
cout<<ans<<'\n';
}
}