#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define N 500100
ll T,n,fa[N],fa2[N],bz1[N],bz2[N],ans;
pair<ll,ll>t1[N],t2[N];
char s1[N],s2[N],lim1[N],lim2[N];
ll find(ll x)
{
    if(x==fa[x]) return x;
    else return fa[x]=find(fa[x]);
}
void uni(ll x,ll y)
{
    x=find(x),y=find(y);
    if(x<y) swap(x,y);
    if(x!=y) fa[x]=y;
}
ll find2(ll x)
{
    if(x==fa2[x]) return x;
    else return fa2[x]=find2(fa2[x]);
}
void uni2(ll x,ll y)
{
    x=find2(x),y=find2(y);
    if(x<y) swap(x,y);
    if(x!=y) fa2[x]=y;
}
int main()
{
    freopen("edit.in","r",stdin);
    freopen("edit.out","w",stdout);
    // double Ti=clock();
    cin>>T;
    while(T--)
    {
        ans=0;
        cin>>n>>s1+1>>s2+1>>lim1+1>>lim2+1;
        for(int i=1;i<=n;i++) fa[i]=i,fa2[i]=i;
        for(int i=1;i<=n;i++) t1[i].first=t1[i].second=t2[i].first=t2[i].second=0;
        for(int i=1;i<=n;i++)
        {
            ll now=i;
            if(lim1[i]=='1')
            {
                ll cnt0=0,cnt1=0;
                if(s1[i]=='0') cnt0++;
                else cnt1++;
                while(i<n&&lim1[i+1]=='1')
                {
                    if(s1[i+1]=='1') cnt1++;
                    else cnt0++;
                    i++;
                }
                t1[now]={cnt0,cnt1};
                for(int j=now;j<=i;j++) uni(now,j);
            }
            else
            {
                while(i<n&&lim1[i+1]=='0') i++;
                for(int j=now;j<=i;j++)
                {
                    if(s1[j]=='0') t1[j]={1,0};
                    else t1[j]={0,1};
                }
            }
        }
        for(int i=1;i<=n;i++)
        {
            ll now=i;
            if(lim2[i]=='1')
            {
                ll cnt0=0,cnt1=0;
                if(s2[i]=='0') cnt0++;
                else cnt1++;
                while(i<n&&lim2[i+1]=='1')
                {
                    if(s2[i+1]=='1') cnt1++;
                    else cnt0++;
                    i++;
                }
                t2[now]={cnt0,cnt1};
                for(int j=now;j<=i;j++) uni2(now,j);
            }
            else
            {
                while(i<n&&lim2[i+1]=='0') i++;
                for(int j=now;j<=i;j++)
                {
                    if(s2[j]=='0') t2[j]={1,0};
                    else t2[j]={0,1};
                }
            }
        }
        for(int i=1;i<=n;i++) bz1[i]=find(i),bz2[i]=find2(i);
        // for(int i=1;i<=n;i++)
        // {
        //     cout<<t1[bz1[i]].first<<" "<<t1[bz1[i]].second<<" "<<t2[bz2[i]].first<<" "<<t2[bz2[i]].second<<endl;
        // }
        for(int i=1;i<=n;i++)
        {
            ll s1cnt1=t1[bz1[i]].second,s1cnt0=t1[bz1[i]].first;
            ll s2cnt1=t2[bz2[i]].second,s2cnt0=t2[bz2[i]].first;
            if(s1cnt0&&s2cnt0)
            {
                t1[bz1[i]].first--;
                t2[bz2[i]].first--;
                ans++;
            }
            else if(s1cnt1&&s2cnt1)
            {
                t1[bz1[i]].second--;
                t2[bz2[i]].second--;
                ans++;
            }
            else if(s1cnt0&&s2cnt1)
            {
                t1[bz1[i]].first--;
                t2[bz2[i]].second--;
            }
            else
            {
                t1[bz1[i]].second--;
                t2[bz2[i]].first--;
            }
        }
        cout<<ans<<endl;
    }
    // cerr<<(double)(clock()-Ti)/CLOCKS_PER_SEC;
    return 0;
}