#include<bits/stdc++.h>
using namespace std;
long long a[500005];
string s1,s2,t1,t2;
void solve()
{
    long long n,sum0=0,sum1=0,Sum0=0,Sum1=0,ans=0,lst0=0,lst1=0,Lst0=0,Lst1=0,flag=0;
    scanf("%lld",&n);
    cin>>s1>>s2>>t1>>t2;
    s1=' '+s1,s2=' '+s2;
    t1=' '+t1,t2=' '+t2;
    if(t1==t2)
    {
        for(long long i=1;i<=n;i++)
        {
            if(t1[i]==0)
            {
                ans+=min(sum0,Sum0)+min(sum1,Sum1),sum0=0,sum1=0,Sum0=0,Sum1=0;
                if(s1[i]==s2[i])ans++;
                continue; 
            }
            if(s1[i]=='0')sum0++;
            if(s1[i]=='1')sum1++;
            if(s2[i]=='0')Sum0++;
            if(s2[i]=='1')Sum1++;
        }
        ans+=min(sum0,Sum0)+min(sum1,Sum1);
        cout<<ans<<'\n';
        return ;
    }
    for(long long i=1;i<=n;i++)if(s1[i]=='0')flag=1;
    if(flag==0)
    {
        for(long long i=1;i<=n;i++) if(s2[i]=='1')ans++;
        cout<<ans<<'\n';
        return ;
    }
    for(long long i=1;i<=n;i++)
    {
        if(t1[i]=='1')
        {
            if(s1[i]=='0')sum0++,Lst0++;
            if(s1[i]=='1')sum1++,Lst1++;
        }
        if(t2[i]=='1')
        {
            if(s2[i]=='0')Sum0++,lst0++;
            if(s2[i]=='1')Sum1++,lst1++;
        }
        if(t1[i]=='0')
        {
            if(s1[i]=='0')Lst0++;
            if(s1[i]=='1')Lst1++;
            ans+=min(Lst0,Sum0)+min(Lst1,Sum1);
            Sum0=max(Sum0-min(Lst0,Sum0),0ll),Sum1=max(Sum1-min(Lst1,Sum1),0ll);
            lst0=max(lst0-min(Lst0,Sum0),0ll),lst1=max(lst1-min(Lst1,Sum1),0ll);
            Lst0=max(Lst0-min(Lst0,Sum0),0ll),Lst1=max(Lst1-min(Lst1,Sum1),0ll);
            sum0=0,sum1=0;
        }
        if(t2[i]=='0')
        {
            if(s2[i]=='0')lst0++;
            if(s2[i]=='1')lst1++;
            ans+=min(lst0,sum0)+min(lst1,sum1);
            Lst0=max(Lst0-min(lst0,sum0),0ll),Lst1=max(Lst1-min(lst1,Sum1),0ll);
            sum0=max(sum0-min(lst0,sum0),0ll),sum1=max(sum1-min(lst1,Sum1),0ll);
            lst0=max(lst0-min(lst0,sum0),0ll),lst1=max(lst1-min(lst1,Sum1),0ll);
            Sum0=0,Sum1=0;
        }
        if(t1[i]=='0'&&t2[i]=='0'&&s1[i]==s2[i])ans++;
    }
    cout<<ans<<endl;
}
int main()
{
	freopen("exit.in","r",stdin);
    freopen("exit.out","w",stdout);
    long long T;
    cin>>T;
    while(T--)solve();
}
