#include<bits/stdc++.h>
using namespace std;

const int M=1e5+5;
int t,n,a[M],b[M],sa[M],sb[M],ta,tb,cnt,ans,saz,sao,sbz,sbo,nwb;
char c;
void doit(){
	if(sbo>sao){
		sbo-=sao;
		ans+=sao;
		sao=0;
	}else{
		sao-=sbo;
		ans+=sbo;
		sbo=0;
	}
	if(sbz>saz){
		sbz-=saz;
		ans+=saz;
		saz=0;
	}else{
		saz-=sbz;
		ans+=sbz;
		sbz=0;
	}
	if(saz>0&&sbo>0){
		if(saz>sbo)saz-=sbo,sbo=0;
		else sbo-=saz,saz=0;
	}else if(sao>0&&sbz>0){
		if(sao>sbz)sao-=sbz,sbz=0;
		else sbz-=sao,sao=0;
	}
}
int main(){
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	scanf("%d",&t);
	while(t--){
		scanf("%d",&n);
//		cout<<"n="<<n<<endl;
		cnt=ans=ta=tb=0;
		for(int i=1;i<=n;++i){
			c=getchar();
			while(c!='0'&&c!='1')c=getchar();
			a[i]=(c=='1');
		}
		for(int i=1;i<=n;++i){
			c=getchar();
			while(c!='0'&&c!='1')c=getchar();
			b[i]=(c=='1');
		}
		a[n+1]=0,b[n+1]=1;
		for(int i=1;i<=n;++i){
			c=getchar();
			while(c!='0'&&c!='1')c=getchar();
			if(c=='0'){
				sa[++ta]=i;
			}
		}
		sa[++ta]=n+1;
		for(int i=1;i<=n;++i){
			c=getchar();
			while(c!='0'&&c!='1')c=getchar();
			if(c=='0'){
				sb[++tb]=i;
			}
		}
		sb[++tb]=n+1;
		sb[++tb]=n+2;
		saz=0,sao=0,sbz=0,sbo=0,nwb=0;
		for(int i=1;i<=ta;++i){
			for(int j=sa[i-1]+1;j<sa[i];++j){
				if(a[j]==1)sao++;
				else saz++;
			}
			if(sb[nwb]<sa[i]){
				if(nwb!=0&&sb[nwb]>sa[i-1]){
					if(b[sb[nwb]]==0)sbz++;
					else sbo++;
				}
				while(sb[nwb+1]<sa[i]&&nwb<=tb){
					for(int j=sb[nwb]+1;j<=sb[nwb+1];++j){
						if(b[j]==0)sbz++;
						else sbo++;
					}
					nwb++;
				}
				doit();
				for(int j=sb[nwb]+1;j<sb[nwb+1];j++){
					if(b[j]==0)sbz++;
					else sbo++;
				}
				nwb++; 
			}
			doit();
			if(sb[nwb]==sa[i]){
				ans+=(b[sb[nwb]]==a[sa[i]]);
			}else{
				if(a[sa[i]]==0){
					if(sbz)sbz--,ans++;
					else sbo--;
				}else{
					if(sbo)sbo--,ans++;
					else sbz--;
				} 
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}
