#include <bits/stdc++.h>
using namespace std;
    int n;
    int t;
    int num1[2],num2[2];//0 and 1 number in a block;
    int r1=1,r2=1;//the block occupies where
    int block1,block2;
    int samenum;
    int min1,min0;
    string s1,s2;
    string t1,t2;
#define MIN(A,B) ((A)>(B))?(B):(A)
#define MAX(A,B) ((A)>(B))?(A):(B)
int k;

int main(){
    freopen("edit.in","r",stdin);
    freopen("edit.out","w",stdout);
    
    cin>>t;
    for(int group=1;group<=t;group++){
        //clear buff
        samenum=0;
        s1="0";s2="0";t1="0";t2="0";
        r1=1;r2=1;
        block1=0;block2=0;
        k=0;
        //clear finished
        cin>>n;
        cin>>s1>>s2;
        cin>>t1>>t2;
        do{
            //fprintf(stderr,"r1=%d,r2=%d\n",r1,r2);
            

            if((t1[r1-1]=='0'||r1==n)&&!block1){
                block1=1;
                num1[(int)(s1[r1-1]-'0')]++;
                //fprintf(stderr,"\tnum1[%d]++",s1[r1-1]-'0');
                //fprintf(stderr,"block1\n");
            }
            if((t2[r2-1]=='0'||r2==n)&&!block2){
                block2=1;
                num2[(int)(s2[r2-1]-'0')]++;
                //fprintf(stderr,"\tnum2[%d]++",s2[r2-1]-'0');
                //fprintf(stderr,"block2,\n",t2[r2-1]);
            }       
            if(!block1){   
                num1[(int)(s1[r1-1]-'0')]++;
                //fprintf(stderr,"\tnum1[%d]++",s1[r1-1]-'0');
                r1++;
            }
            if(!block2){
                num2[(int)(s2[r2-1]-'0')]++;
                //fprintf(stderr,"\tnum2[%d]++",s2[r2-1]-'0');
                r2++;
            }
            //fprintf(stderr,"\n");

            if(block1&&block2){//two block are ready
                //fprintf(stderr,"blocks are ready,r1=%d,r2=%d\n",r1,r2);
                //fprintf(stderr,"s1 have:0-%d,1-%d;s2 have:0-%d,1-%d\n",num1[0],num1[1],num2[0],num2[1]);
                min0=MIN(num1[0],num2[0]);
                min1=MIN(num1[1],num2[1]);
                samenum+=min1+min0;
                if(s1[r1-1]==s2[r2-1]&&r1!=r2){//only need which can't move?
                    if(num1[s1[r1-1]-'0']==1&&num2[s2[r2-1]-'0']==1)
                        samenum--;
                }
                //fprintf(stderr,"samenum=%d=%d+%d\n",samenum,min0,min1);
                num1[0]-=min0;num2[0]-=min0;
                num1[1]-=min1;num2[1]-=min1;
                if(r1>=r2){//block1 goes farther than block2
//                    //fprintf(stderr,"block1 farther");
                    if(num2[0]){//block2 still have 0
                        num1[1]-=num2[0];
                        num2[0]=0;
                    }
                    else{//block2 still have 1
                        num1[0]-=num2[1];
                        num2[1]=0;
                    }
                    if(r2!=n){
                        block2=0;
                        r2=r2+1;
                    }
                    
                }
                else{//block2 goes farther than block1
                    if(num1[0]){//block1 still have 0
                        num2[1]-=num1[0];
                        num1[0]=0;
                    }
                    else{//block1 still have 0
                        num2[0]-=num1[1];
                        num1[1]=0;
                    }
                    if(r1!=n){
                        block1=0;
                        r1=r1+1;
                    }
                    
                }
                //fprintf(stderr,"now,s1 have:0-%d,1-%d;s2 have:0-%d,1-%d\n",num1[0],num1[1],num2[0],num2[1]);
                if(r1==n&&r2==n)k++;
                if(k==2)break;
            }
        }while(1);

        cout<<samenum<<endl;
        //fprintf(stderr,"%d\n",samenum);
    }
}
 
