#include <stdio.h>
#include <vector>
using namespace std;
bool s1[100001],s2[100001],t1[100001],t2[100001];
int n,best;
//vector<int> pre1,cindex1;
vector< vector<bool> >  ss1;
void trap1(int _cindex)
{
    if(s1[_cindex] == s1[_cindex+1])
        return;
    bool _tmp = s1[_cindex];
    s1[_cindex] = s1[_cindex+1];
    s1[_cindex+1] = _tmp; 
}
void trap2(int _cindex)
{
    if(s2[_cindex] == s2[_cindex+1])
        return;
    bool _tmp = s2[_cindex];
    s2[_cindex] = s2[_cindex+1];
    s2[_cindex+1] = _tmp; 
}
int count(int _index)
{
    int _res = 0;
    for(int i = 0;i < n;i++)
        if(ss1[_index][i]==s2[i])
            _res ++;
    return _res;
}
void dfs1(int _pre,int _cindex)
{
    if(_pre != -1)
    {
        if(_cindex == n-1)
            return;
        if(!t1[_cindex]||!t1[_cindex+1])
            return;
        trap1(_cindex);
        //pre1.push_back(_pre);
        //cindex1.push_back(_cindex);
    }
    vector<bool> _tmp;
    for(int i = 0;i < n;i++)
    {
        _tmp.push_back(s1[i]);
    }
    ss1.push_back(_tmp);
    int _this = ss1.size();
    for(int i = _cindex+1;i < n-1;i++)
        dfs1(_this,i);
    if(_pre != -1)
        trap1(_cindex);
}
void dfs2(int _cindex)
{
    if(_cindex != -1)
    {
        if(_cindex == n-1)
            return;
        if(!t2[_cindex]||!t2[_cindex+1])
            return;
        trap2(_cindex);
    }
    int _tmp;
    for(int i = 0;i < ss1.size();i++)
    {        
        _tmp = count(i);
        if(_tmp > best)best = _tmp;
    }
    for(int i = _cindex+1;i < n-1;i++)
        dfs2(i);
    if(_cindex != -1)
        trap2(_cindex);
}
int main(){
    freopen("edit.in","r",stdin);
    freopen("edit.out","w",stdout);

    int T = 0;
    scanf("%d",&T);
    
    while(T-- > 0)
    {
        bool isA = true;
        // Accept Data        
        scanf("%d ",&n);
        bool flag1 = false;
        bool flag2 = false;
        int aCnt = 0;
        for(int i = 0;i < n;i++)
        {
            char _tmp;
            scanf("%c",&_tmp);
            if(_tmp == '0')
            {
                s1[i] = false;
                if(!flag1)
                {
                    flag1 = true;
                    flag2 = false;
                }
                else
                {
                    if(flag2)
                        isA = false;
                }
            }
            else
            {
                s1[i] = true; 
                if(!flag1)
                {
                    flag1 = true;
                    flag2 = true;
                }
                else
                {
                    if(!flag2)
                        isA = false;
                }
            }           
        }
        getchar();
        for(int i = 0;i < n;i++)
        {
            char _tmp;
            scanf("%c",&_tmp);
            if(_tmp == '0')
                s2[i] = false;
            else
                s2[i] = true;
            if(flag2 == s2[i])aCnt ++;            
        }
        getchar();
        for(int i = 0;i < n;i++)
        {
            char _tmp;
            scanf("%c",&_tmp);
            if(_tmp == '0')
                t1[i] = false;
            else
                t1[i] = true;            
        }
        getchar();
        for(int i = 0;i < n;i++)
        {
            char _tmp;
            scanf("%c",&_tmp);
            if(_tmp == '0')
                t2[i] = false;
            else
                t2[i] = true;            
        }
        // Response
        if(isA)
        {
            printf("%d\n",aCnt);
            continue;
        }
        dfs1(-1,-1);
        best = 0;
        dfs2(-1);
        printf("%d\n",best);
    }    
    fclose(stdin);
    fclose(stdout);
    return 0;
    //Hope It Works!
}