#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
int n,t;
char s[N];
int a[N],b[N],Ra[N],Rb[N]; 
void inpu()
{
	scanf("%d",&n);
	scanf("%s",s+1);
	for(int i=1;i<=n;i++)
		a[i]=s[i]-'0';
	scanf("%s",s+1);
	for(int i=1;i<=n;i++)
		b[i]=s[i]-'0';
	scanf("%s",s+1);
	for(int i=1;i<=n;i++)
		Ra[i]=s[i]-'0';
	scanf("%s",s+1);
	for(int i=1;i<=n;i++)
		Rb[i]=s[i]-'0';
}
int ans=0;
struct Ps
{
	int c1,c0,l,r;
};
vector<Ps> A,B;
int main()
{
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	scanf("%d",&t);
	while(t--)
	{
		ans=0;
		vector<Ps> A,B;
		inpu();
		a[n+1]=2;
		b[n+1]=3;
		Ra[n+1]=Rb[n+1]=0;
		int tmp1=0,tmp0=0,L=1;
		for(int i=1;i<=n+1;i++)
		{
			if(Ra[i]==0)
			{
				if(i!=L)
					A.push_back({tmp1,tmp0,L,i-1});
				tmp1=tmp0=0;
				L=i+1;
				continue;
			}
			if(a[i]==1)
				tmp1++;
			else
				tmp0++;
		}
		tmp1=0,tmp0=0,L=1;
		for(int i=1;i<=n+1;i++)
		{
			if(Rb[i]==0)
			{
				if(i!=L)
					B.push_back({tmp1,tmp0,L,i-1});
				tmp1=tmp0=0;
				L=i+1;
				continue;
			}
			if(b[i]==1)
				tmp1++;
			else
				tmp0++;
		}
//		for(Ps x:A)
//		{
//			printf("%d %d %d %d\n",x.c1,x.c0,x.l,x.r);
//		}
//		for(Ps x:B)
//		{
//			printf("%d %d %d %d\n",x.c1,x.c0,x.l,x.r);
//		}
		int pvta=0,pvtb=0;
		for(int i=1;i<=n;i++)
		{
//			printf("%d:%d\n",i,ans);
//			printf("%d %d %d %d\n",A[pvta].c1,A[pvta].c0,B[pvtb].c0,B[pvtb].c0);
			if(!Ra[i]&&!Rb[i])
			{
				ans+=(a[i]==b[i]?1:0);
				continue;
			}
			if(pvtb!=B.size()-1)
			{
				if(i==B[pvtb+1].l)
					pvtb++;
			}
			if(pvta!=A.size()-1)
			{
				if(i==A[pvta+1].l)
					pvta++; 
			}
			if(!Ra[i])
			{
				if(a[i]==1)
				{
					if(B[pvtb].c1>0)
						B[pvtb].c1--,ans++;
					else
						B[pvtb].c0--;
				}
				else
				{
					if(B[pvtb].c0>0)
						B[pvtb].c0--,ans++;
					else
						B[pvtb].c1--;
				}
				continue;
			}
			if(!Rb[i])
			{
				if(b[i]==1)
				{
					if(A[pvta].c1>0)
						A[pvta].c1--,ans++;
					else
						A[pvta].c0--;
				}
				else
				{
					if(A[pvta].c0>0)
						A[pvta].c0--,ans++;
					else
						A[pvta].c1--;
				}
				continue;
			}
			if(i==A[pvta].r)
			{
				ans+=min(A[pvta].c1,B[pvtb].c1)+min(A[pvta].c0,B[pvtb].c0);
				int d1=min(A[pvta].c1,B[pvtb].c1),d0=min(A[pvta].c0,B[pvtb].c0);
				B[pvtb].c1-=d1;
				B[pvtb].c0-=d0;
				A[pvta].c1-=d1;
				A[pvta].c0-=d0;
				int lst=A[pvta].c1+A[pvta].c0;
				if(B[pvtb].c1>B[pvtb].c0)
					B[pvtb].c1-=lst;
				else
					B[pvtb].c0-=lst;
			}
			else if(i==B[pvtb].r)
			{
				ans+=min(A[pvta].c1,B[pvtb].c1)+min(A[pvta].c0,B[pvtb].c0);
				int d1=min(A[pvta].c1,B[pvtb].c1),d0=min(A[pvta].c0,B[pvtb].c0);
				B[pvtb].c1-=d1;
				B[pvtb].c0-=d0;
				A[pvta].c1-=d1;
				A[pvta].c0-=d0;
				int lst=B[pvtb].c1+B[pvtb].c0;
				if(A[pvta].c1>A[pvta].c0)
					A[pvta].c1-=lst;
				else
					A[pvta].c0-=lst;
			}
		}
		printf("%d\n",ans); 
	}
	return 0;
}
