#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5;
struct Node{int l,r,c0,c1;};
int n;
char s1[maxn+5],s2[maxn+5];
char t1[maxn+5],t2[maxn+5];
Node a1[maxn+5],a2[maxn+5];
int tt1,tt2;
int ans;
inline void Calc(Node &x,Node &y){
    int t;
    t=min(x.c0,y.c0);
    x.c0-=t;
    x.c1-=y.c0-t;
    ans+=t;
    t=min(x.c1,y.c1);
    x.c1-=t;
    x.c0-=y.c1-t;
    ans+=t;
}
inline void Solve(){
    scanf("%d",&n);
    scanf("%s%s%s%s",s1+1,s2+1,t1+1,t2+1);
    tt1=tt2=0;
    int c0=0,c1=0,lst=0;
    for(int i=1;i<=n;i++){
        if(t1[i]=='0'){
            if(lst+1<=i-1)
                a1[++tt1]=Node({lst+1,i-1,c0,c1});
            lst=i;
            c0=c1=0;
        }
        if(s1[i]=='0') c0++;
        else c1++;
        if(t1[i]=='0'){
            a1[++tt1]=Node({i,i,c0,c1});
            c0=c1=0;
        }
    }
    if(lst+1<=n)
        a1[++tt1]=Node{lst+1,n,c0,c1};
    c0=c1=0,lst=0;
    for(int i=1;i<=n;i++){
        if(t2[i]=='0'){
            if(lst+1<=i-1)
                a2[++tt2]=Node({lst+1,i-1,c0,c1});
            lst=i;
            c0=c1=0;
        }
        if(s2[i]=='0') c0++;
        else c1++;
        if(t2[i]=='0'){
            a2[++tt2]=Node({i,i,c0,c1});
            c0=c1=0;
        }
    }
    if(lst+1<=n)
        a2[++tt2]=Node{lst+1,n,c0,c1};
    ans=0;
    for(int i=1,j=1;i<=tt1;i++){
        for(;j<=tt2&&a2[j].r<=a1[i].r;j++)
            Calc(a1[i],a2[j]);
        if(a1[i].c0==0&&a1[i].c1==0)
            continue;
        Calc(a2[j],a1[i]);
    }
    printf("%d\n",ans);
}
signed main(){
    freopen("edit.in","r",stdin);
    // freopen("edit2.in","r",stdin);
    // system("fc edit2.ans edit.out");return 0;
    freopen("edit.out","w",stdout);
    int tcnt;scanf("%d",&tcnt);
    while(tcnt--) Solve();
    return 0;
}