#include<bits/stdc++.h>
#define pb push_back
using namespace std;
const int N=1e5+5;
int n,SA[N],SB[N];
struct Line{int L,R;};
char A[N],B[N],C[N],D[N];
inline int QryA1(Line X){return SA[X.R]-SA[X.L-1];}
inline int QryA0(Line X){return X.R-X.L+1-(SA[X.R]-SA[X.L-1]);}
inline int QryB1(Line X){return SB[X.R]-SB[X.L-1];}
inline int QryB0(Line X){return X.R-X.L+1-(SB[X.R]-SB[X.L-1]);}
inline void Work()
{
	scanf("%d",&n);
	scanf("%s",A+1);
	scanf("%s",B+1);
	scanf("%s",C+1);
	scanf("%s",D+1);
	vector<Line>LA,LB;
	for(int i=1;i<=n;i++)SA[i]=SA[i-1]+(A[i]=='1');
	for(int i=1;i<=n;i++)SB[i]=SB[i-1]+(B[i]=='1');	 
	for(int i=1,L=0;i<=n;i++)
	{
		if(C[i]=='0')
		{
			LA.pb({L+1,i-1}),LA.pb({i,i});
			L=i;	
		}
		else if(i==n)LA.pb({L+1,i});
	}
	for(int i=1,L=0;i<=n;i++)
	{
		if(D[i]=='0')
		{
			LB.pb({L+1,i-1}),LB.pb({i,i});
			L=i;	
		}
		else if(i==n)LB.pb({L+1,i});
	}	
	int A1=QryA1(LA[0]),A0=QryA0(LA[0]),t1=0;
	int B1=QryB1(LB[0]),B0=QryB0(LB[0]),t2=0;
	int P=1,Ans=0;
	while(t1<(int)LA.size()&&t2<(int)LB.size()) 
	{
		int K1=min(A1,B1),K0=min(A0,B0);
	//	if(n==1000&&(int)LA.size()==3)cout<<P<<' '<<min(LA[t1].R,LB[t2].R)<<' '<<A1<<' '<<A0<<' '<<B1<<' '<<B0<<' '<<Ans+K1+K0<<endl;
		A1-=K1,B1-=K1,A0-=K0,B0-=K0; 
		Ans+=K1+K0;
		P=min(LA[t1].R,LB[t2].R)+1;
		if(P>LA[t1].R)
		{
			//if(n==1000&&(int)LA.size()==3)cout<<"Out"<<A1<<' '<<A0<<endl; 
			B0-=A1,B1-=A0; 
			t1++;
			if(t1!=(int)LA.size())A1=QryA1(LA[t1]),A0=QryA0(LA[t1]);
		}
		if(P>LB[t2].R)
		{
			A0-=B1,A1-=B0; 
			t2++;
			if(t2!=(int)LB.size())B1=QryB1(LB[t2]),B0=QryB0(LB[t2]);
		}
	}
	printf("%d\n",Ans);
}
int main()
{
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	int T;scanf("%d",&T);
	while(T--)Work();
}
//This is my war. 
//Nirvana or Death.
//DengDuck. 
