#include<bits/stdc++.h>
#define inf 0x3f3f3f3f
using namespace std;
int xx;char ff,chh;inline int read(){
    xx=ff=0;while(!isdigit(chh)){if(chh=='-'){ff=1;}chh=getchar();}
    while(isdigit(chh)){xx=(xx<<1)+(xx<<3)+chh-'0';chh=getchar();}return ff? -xx: xx;
}
const int N=2e5;
void sr_init(){freopen("edit.in","r",stdin);freopen("edit.out","w",stdout);}
char s1[N],s2[N];
char can1[N],can2[N];
struct node{
    int v0,v1;
    inline int len(){return v0+v1;}
};
vector<node> a,b;
void init(int n,char can[],char s[],vector<node> &a);
void solve();
int main(){
    sr_init();
    int G=read();
    while(G--){
        solve();
    }

    return 0;
}
void solve(){
    int n=read(),p1=0,p2=0,ans=0;
    //printf("***%d**\n",n);
    a.clear();b.clear();
    memset(s1,0,sizeof(s1));
    memset(s2,0,sizeof(s1));
    memset(can1,0,sizeof(can1));
    memset(can2,0,sizeof(can2));
    scanf("%s%s%s%s",s1,s2,can1,can2);
    can1[n]='0';can2[n]='0';
    s1[n]=0;s2[n]=0;
    init(n,can1,s1,a);
    init(n,can2,s2,b);
    //for(auto i: a){printf("%d %d   ",i.v0,i.v1);}putchar(10);
    //for(auto i: b){printf("%d %d   ",i.v0,i.v1);}putchar(10);
    for(;p1<(int)a.size() && p2<(int)b.size();){
        node &t1=a[p1],&t2=b[p2];
        if(t1.len()>t2.len()){
            ans+=min(t1.v0,t2.v0);
            ans+=min(t1.v1,t2.v1);
            if(t1.v0>=t2.v0){t1.v0-=t2.v0;}
            else{t1.v1-=(t2.v0-t1.v0);t1.v0=0;}
            if(t1.v1>=t2.v1){t1.v1-=t2.v1;}
            else{t1.v0-=(t2.v1-t1.v1);t1.v1=0;}
            ++p2;
        }
        else if(t1.len()<t2.len()){
            ans+=min(t1.v0,t2.v0);
            ans+=min(t1.v1,t2.v1);
            if(t1.v0<=t2.v0){t2.v0-=t1.v0;}
            else{t2.v1-=(t1.v0-t2.v0);t2.v0=0;}
            if(t1.v1<=t2.v1){t2.v1-=t1.v1;}
            else{t2.v0-=(t1.v1-t2.v1);t2.v1=0;}
            ++p1;
        }
        else{
            ans+=min(t1.v0,t2.v0);
            ans+=min(t1.v1,t2.v1);
            ++p1,++p2;
        }
        //printf("%d %d   %d %d\n",t1.v0,t1.v1,t2.v0,t2.v1);
    }
    printf("%d\n",ans);
}
void init(int n,char can[],char s[],vector<node> &a){
    int ls=0;
    for(int i=0;i<=n;++i){
        if(can[i]=='0'){
            int v0=0,v1=0;
            for(;ls<i;++ls){
                v0+=(s[ls]=='0');
                v1+=(s[ls]=='1');
            }
            if(v0!=0 || v1!=0){a.push_back({v0,v1});}
            if(s[i]=='0'){a.push_back({1,0});}
            else if(s[i]=='1'){a.push_back({0,1});}
            ls=i+1;
        }
    }
}
