#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
const int N=1e6+1;
struct node{
	long long st,ed,sum1,sum0;
}ax[N],bx[N];
long long Z,a,cnta,cntb;
string stra,strb,strc,strd;
inline void work()
{
	long long sum=0,x=1,y=1,tmp1,tmp2;
	while(x<=cnta&&y<=cntb)
	{
		tmp1=min(ax[x].sum0,bx[y].sum0);
		tmp2=min(ax[x].sum1,bx[y].sum1);
//		printf("%lld %lld\n%lld %lld %lld %lld %lld %lld\n",x,y,tmp1,tmp2,ax[x].sum0,ax[x].sum1,bx[y].sum0,bx[y].sum1); 
		sum+=tmp1;
		sum+=tmp2;
		ax[x].sum0-=tmp1;
		bx[y].sum0-=tmp1;
		ax[x].sum1-=tmp2;
		bx[y].sum1-=tmp2;
		if(ax[x].ed<bx[y].ed)x++;
		else{
			if(ax[x].ed==bx[y].ed)
			{
				x++;
				y++;
			}else y++;
		}
	}
	printf("%lld\n",sum);
}
inline void init()
{
	cnta=cntb=1;
	for(int i=1;i<=a;i++)
	{
		ax[i].ed=ax[i].st=ax[i].sum0=ax[i].sum1=0;
		bx[i].ed=bx[i].st=bx[i].sum0=bx[i].sum1=0;
	}
}
int main()
{
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	scanf("%lld",&Z);
	ax[0].ed=bx[0].ed=-1;
	while(Z--)
	{
		scanf("%lld",&a);
		cin>>stra>>strb>>strc>>strd;
		cnta=cntb=1;
		init();
		for(int i=0;i<a;i++)
		{
			if(strc[i]=='0')
			{
				ax[cnta].ed=i-1;
				ax[++cnta].st=ax[cnta].ed=i;
				if(stra[i]=='0')ax[cnta].sum0=1;
				else ax[cnta].sum1=1;
				cnta++;
			}else{
				ax[cnta].st=ax[cnta-1].ed+1;
				if(stra[i]=='0')ax[cnta].sum0++;
				else ax[cnta].sum1++;
			}
			if(strd[i]=='0')
			{
				bx[cntb].ed=i-1;
				bx[++cntb].st=bx[cntb].ed=i;
				if(strb[i]=='0')bx[cntb].sum0=1;
				else bx[cntb].sum1=1;
				cntb++;
			}else{
				bx[cntb].st=bx[cntb-1].ed+1;
				if(strb[i]=='0')bx[cntb].sum0++;
				else bx[cntb].sum1++;
			}
		}
		if(strc[a-1]=='1')ax[cnta].ed=a-1;
		else cnta--;
		if(strd[a-1]=='1')bx[cntb].ed=a-1;
		else cntb--;
//		puts("A");
//		for(int i=1;i<=cnta;i++)printf("%lld %lld %lld %lld\n",ax[i].st,ax[i].ed,ax[i].sum0,ax[i].sum1);
//		puts("B");
//		for(int i=1;i<=cntb;i++)printf("%lld %lld %lld %lld\n",bx[i].st,bx[i].ed,bx[i].sum0,bx[i].sum1);
//		printf("\n case %lld:\n",Z); 
		work();
	}
}//nlogn
