#include<bits/stdc++.h>
using namespace std;
int T;
const int maxn=200010;
bool s1[maxn],s2[maxn];
bool c1[maxn],c2[maxn];
struct x{
	int js0;
	int js1;
}f1[maxn],f2[maxn];
int n;
int ans;
char temp;
void work(){
	
	cin>>n;
	ans=0;
	int jsx1=0,jsx2=0;
	for(int i=1;i<=n;i++){
		cin>>temp;
		s1[i]=temp-'0';
	}
	for(int i=1;i<=n;i++){
		cin>>temp;
		s2[i]=temp-'0';
	}
	int jstemp0=0,jstemp1=0;
	for(int i=1;i<=n;i++){
		cin>>temp;
		c1[i]=temp-'0';
		if(c1[i]==0){
			x tempx;
			tempx.js0=jstemp0;
			tempx.js1=jstemp1;
			jstemp0=0;
			jstemp1=0;
			f1[jsx1++]=tempx;
			tempx.js0=0;tempx.js1=0;
			if(s1[i]==0)tempx.js0=1;
			else tempx.js1=1;
			f1[jsx1++]=tempx;
			continue;
		}
		if(s1[i])jstemp1++;
		else jstemp0++;
	}
	x tempxx;
	tempxx.js0=jstemp0;
	tempxx.js1=jstemp1;
	jstemp0=0;
	jstemp1=0;
	f1[jsx1++]=tempxx;
	for(int i=1;i<=n;i++){
		cin>>temp;
		c2[i]=temp-'0';
		if(c2[i]==0){
			x tempx;
			tempx.js0=jstemp0;
			tempx.js1=jstemp1;
			jstemp0=0;
			jstemp1=0;
			f2[jsx2++]=tempx;
			tempx.js0=0;tempx.js1=0;
			if(s2[i]==0)tempx.js0=1;
			else tempx.js1=1;
			f2[jsx2++]=tempx;
			continue;
		}
		if(s2[i])jstemp1++;
		else jstemp0++;
	}
	tempxx.js0=jstemp0;
	tempxx.js1=jstemp1;
	f2[jsx2++]=tempxx;
	int xp1=0,xp2=0;
	int s1js0=0,s2js0=0,s1js1=0,s2js1=0;
	while(1){
		if(xp1>=jsx1&&xp2>=jsx2)break;
		if(s1js0+s1js1==0){
			
			s1js0+=f1[xp1].js0;
			s1js1+=f1[xp1].js1;
			xp1++;
		}
		if(s2js0+s2js1==0){
		//	printf("xp2 %d  js0 %d  js1 %d\n",xp2,f2[xp2].js0,f2[xp2].js1);
			s2js0+=f2[xp2].js0;
			s2js1+=f2[xp2].js1;
			xp2++;
		}
		int min0=min(s1js0,s2js0);
		int min1=min(s1js1,s2js1);
		ans+=min0;
		ans+=min1;
	//	printf("min0: %d min1: %d\n",min0,min1);
		s1js0-=min0;
		s2js0-=min0;
		s1js1-=min1;
		s2js1-=min1;
		if(s1js1+s1js0>s2js1+s2js0){
			if(s1js1>0)s1js1-=s2js1+s2js0;
			else s1js0-=s2js1+s2js0;
			s2js1=s2js0=0; 
		}else{
			if(s2js1>0)s2js1-=s1js1+s1js0;
			else s2js0-=s1js1+s1js0;
			s1js1=s1js0=0;
		}
	}
	printf("%d\n",ans);
	return;
}
int main(){
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	cin>>T;
	while(T--){
		work();
	}
	
} 
