#include <bits/stdc++.h>

#define int long long

using namespace std;

#define fileio(x,y) freopen(x,"r",stdin),freopen(y,"w",stdout)
#define tup tuple<int,int,int>
#define pii pair<int,int>
#define pb emplace_back
#define i12 __int128_t
#define mt make_tuple
#define mp make_pair

const int   mod=998244353;
const int   maxn=1e5+10;

vector<pii> blk1,blk2;
string      s,t,v1,v2;
int         n;

void work()
{
    /* Code */
    blk1.clear(),blk2.clear();
    cin>>n; int s0=0,s1=0;
    cin>>s>>t>>v1>>v2;
    for(int i=0; i<n; i++)
    {
        if(v1[i]=='0')
        {
            if(s0||s1) blk1.pb(s0,s1);
            blk1.pb(s[i]=='0',s[i]=='1'),s0=s1=0;
        }
        else s0+=(s[i]=='0'),s1+=(s[i]=='1');
    }
    if(s0||s1) blk1.pb(s0,s1);
    s0=s1=0;
    for(int i=0; i<n; i++)
    {
        if(v2[i]=='0')
        {
            if(s0||s1) blk2.pb(s0,s1);
            blk2.pb(t[i]=='0',t[i]=='1'),s0=s1=0;
        }
        else s0+=(t[i]=='0'),s1+=(t[i]=='1');
    }
    if(s0||s1) blk2.pb(s0,s1);
    // for(auto [s0,s1]:blk1) cout<<s0<<' '<<s1<<'\n'; cout<<'\n';
    // for(auto [s0,s1]:blk2) cout<<s0<<' '<<s1<<'\n'; cout<<'\n';
    int p1=0,pos1=0,p2=0,pos2=0,tar=0;
    pii l1,l2,lst1,lst2;
    while(p1<n||p2<n)
    {
        int leftSize=0;
        if(p1<=p2)
        {
            pii now=blk1[pos1++]; l1=lst1=now;
            leftSize=min(p2-p1,now.first+now.second);
            p1+=now.first+now.second;
        }
        else
        {
            pii now=blk2[pos2++]; l2=lst2=now;
            leftSize=min(p1-p2,now.first+now.second);
            p2+=now.first+now.second;
        }
        // cout<<"BEF "<<p1<<' '<<l1.first<<' '<<l1.second<<' '<<p2<<' '<<l2.first<<' '<<l2.second<<' '<<tar<<' '<<leftSize<<'\n';
        if(p1-lst1.first-lst1.second>=p2) continue;
        if(p2-lst2.first-lst2.second>=p1) continue;
        int t1=min(l1.first,l2.first);
        int t2=min(l1.second,l2.second);
        tar+=min(leftSize,t1+t2);
        if(t1+t2>leftSize)
        {
            int left=t1+t2-leftSize;
            int temp=min(t2,left); t2-=temp,left-=temp;
            if(left) { temp=min(t1,left); t1-=temp,left-=temp; }
        }
        l1.first-=t1,l2.first-=t1;
        l1.second-=t2,l2.second-=t2;
        // cout<<"AFT "<<p1<<' '<<l1.first<<' '<<l1.second<<' '<<p2<<' '<<l2.first<<' '<<l2.second<<' '<<tar<<' '<<leftSize<<'\n';
    }
    cout<<tar<<'\n';
    return;
}

signed main()
{
    fileio("edit.in","edit.out");
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t,stTime=clock();
    cin>>t;
    while(t--) work();
    // cerr<<"Time : "<<(double)(clock()-stTime)/CLOCKS_PER_SEC<<'\n';
    return 0;
}