#include<cstdio>
#include<cctype>
#include<string>
#include<iostream>
using namespace std;
template<typename _Tp>
inline void read(_Tp& x){
    static char ch;
    while(ch=getchar(),!isdigit(ch));
    x=(ch^48);
    while(ch=getchar(),isdigit(ch))x=(x<<3)+(x<<1)+(ch^48);
}
template<typename _Tp,typename ..._Args>
inline void read(_Tp& x,_Args &...args){
    read(x);
    read(args...);
}
string s1,s2,t1,t2;
int n,res,cur1[2],cur2[2];
void run(){
    res=0;
    read(n);
    cin>>s1>>s2>>t1>>t2;
    cur1[0]=cur1[1]=cur2[0]=cur2[1]=0;
    for(int i=0;i<n and t1[i]=='1';i++){
        cur1[s1[i]-'0']++;
    }
    for(int i=0;i<n and t2[i]=='1';i++){
        cur2[s2[i]-'0']++;
    }
    for(int i=0;i<n;i++){
        if(!cur1[0] and !cur1[1]){
            if(t1[i]=='1')
                for(int j=i;j<n and t1[j]=='1';j++){
                    cur1[s1[j]-'0']++;
                }
            else cur1[s1[i]-'0']++;
        }
        if(!cur2[0] and !cur2[1]){
            if(t2[i]=='1')
                for(int j=i;j<n and t2[j]=='1';j++){
                    cur2[s2[j]-'0']++;
                }
            else cur2[s2[i]-'0']++;
        }
        res+=((cur1[0] and cur2[0]) or (cur1[1] and cur2[1]));
        if(cur1[0] and cur2[0]){
            cur1[0]--,cur2[0]--;
            continue;
        }
        if(cur1[1] and cur2[1]){
            cur1[1]--,cur2[1]--;
            continue;
        }
        if(cur1[0]){
            cur1[0]--,cur2[1]--;
            continue;
        }
        cur1[1]--,cur2[0]--;
    }
    printf("%d\n",res);
}
int main(){
    freopen("edit.in","r",stdin);
    freopen("edit.out","w",stdout);
    int T=1;
    read(T);
    while(T--)run();
}
/*
8:55 passed all samples.
*/