#include<bits/stdc++.h>
using namespace std;
char sta[100005],stb[100005];
int cka[100005],ckb[100005];
int qza[100005],qzb[100005];
int Nxa0[100005],Nxa1[100005],Nxb0[100005],Nxb1[100005];
void solve(){
	memset(qza,0,sizeof qza);
	memset(qzb,0,sizeof qzb);
	int n,m,i,j,k;
	scanf("%d",&n);
	scanf("%s%s",&sta,&stb);
	qza[0]=sta[0]-'0';
	qzb[0]=stb[0]-'0';
	for(i=1;i<n;i++)
	  qza[i]=qza[i-1]+(sta[i]-'0'),qzb[i]=qzb[i-1]+(stb[i]-'0');
	for(i=0;i<n;++i)
	  scanf("%1d",&cka[i]);
	for(i=0;i<n;i++)
	  scanf("%1d",&ckb[i]);
	if (qza[n-1]==0){
		printf("%d\n",n-qzb[n-1]);
		return;
	}
	if (qzb[n-1]==0){
		printf("%d\n",n-qza[n-1]);
		return;
	}
	if (qza[n-1]==n) {
		printf("%d\n",qzb[n-1]);
		return;
	}
	if (qzb[n-1]==n) {
		printf("%d\n",qza[n-1]);
		return;
	}
	bool tsb=1;
	int ctx0=0,ctx1=0;
	for(i=0;i<n;i++){
	  ctx0+=cka[i],ctx1+=ckb[i];
	  if (cka[i]!=ckb[i])  tsb=0;
	}
	if (tsb) {
		int lst0=-1,ans=0;
		for(i=0;i<n;i++) {
			if (cka[i]==0||i==n-1) {
				if (i==0) {
					ans+=(sta[i]==stb[i]?1:0);
					lst0=i;
				}
				else{
					int nx1=min(qza[i-1]-qza[lst0],qzb[i-1]-qzb[lst0]);
					int nx0=min((i-lst0-1)-(qza[i-1]-qza[lst0]),(i-lst0-1)-(qzb[i-1]-qzb[lst0]));
					ans+=nx1+nx0+(sta[i]==stb[i]?1:0);
					lst0=i;
				}
			}
		}
		printf("%d\n",ans);
		return;
	}
	int na0,na1,nb0,nb1,lsti=0,lstj=0;
	for(i=0;i<n;i++){
	//	for(k=1;k<=3;++k){
		if (sta[i]!=stb[i]) {
			int conf=0;
			if (cka[i]==1) {
				for(j=i+1;j<n&&cka[j];j++)
				  if (cka[j]==1&&sta[j]==stb[i]){
				  	swap(sta[i],sta[j]);
				  	break;
				  }
				if (j>=n||cka[j]==0) conf=1;
			}
			if ((cka[i]==0||conf)&&ckb[i]==1) {
				for(j=i+1;j<n&&ckb[j];j++)
				  if (ckb[j]==1&&stb[j]==sta[i]){
				  	swap(stb[j],stb[i]);
				  	break;
				  }
			}
		} 
	//	}
	}
	int countt=0;
	for(i=0;i<n;i++)
	  if (sta[i]==stb[i]) ++countt;
	printf("%d\n",countt);
}
int main(){
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	int t;
	scanf("%d",&t);
	while(t--) solve();
	fclose(stdin);
	fclose(stdout);
	return 0;
	
}
