#include<bits/stdc++.h>
#define fo(i,x,y) for(int i(x);i<=y;i=-~i)
#define fd(i,x,y) for(int i(x);i>=y;--i)
#define ll long long
using namespace std;
char ST;

const int N=1e5+5;

int T,n,num[2],ans,now[2];
char s[2][N],t[2][N];
struct qj{
    int r,v;
}a[2][N];

int calc(int o,int l,int r){
    int cnt(0);
    fo(i,l,r)if(s[o][i]^48)++cnt;
    return cnt;
}
void solve(){
    scanf("%d",&n);
    fo(o,0,1)scanf("%s",s[o]+1);
    fo(o,0,1)scanf("%s",t[o]+1);
    fo(o,0,1)num[o]=0;
    fo(o,0,1){
        int las(0);
        fo(i,1,n)
        if(t[o][i]=='0')
        {
            if(las+1<=i-1)a[o][++num[o]]=(qj){i-1,calc(o,las+1,i-1)};
            a[o][++num[o]]=(qj){i,s[o][i]^48};
            las=i;
        }
        if(las+1<=n)a[o][++num[o]]=(qj){n,calc(o,las+1,n)};
    }
    ans=0;
    fo(o,0,1)now[o]=1;
    int l(1);
    while(l<=n){
        int o=a[0][now[0]].r<a[1][now[1]].r?0:1,r=a[o][now[o]].r,rr=a[o^1][now[o^1]].r;
        int x=a[o][now[o]].v,cnt=a[o^1][now[o^1]].v,y=cnt<=x?cnt:max(x,cnt+r-rr);
        ans+=abs(x-y);
        if(r==rr){
            ++now[0];++now[1];l=r+1;continue;
        }
        ++now[o];
        a[o^1][now[o^1]].v-=y;
        l=r+1;
    }
    ans=n-ans;
    printf("%d\n",ans);
}

char EN;
int main(){
    freopen("edit.in","r",stdin);freopen("edit.out","w",stdout);
    // cerr<<(&EN-&ST)/1048576.0<<'\n';
    scanf("%d",&T);
    while(T--)solve();
    return 0;
}
