#include<bits/stdc++.h>
using namespace std;
#define max_n 100020
int tid;
int n;
char sa[max_n+2];
char sb[max_n+2];
char ta[max_n+2];
char tb[max_n+2];
int cnta[max_n+2][2];
int cntb[max_n+2][2];
int ansa[max_n+2];
int ansb[max_n+2];
int ans=0;
int main(){
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	scanf("%d",&tid);
	for(int ca=1;ca<=tid;++ca){
		scanf("%d%s%s%s%s",&n,sa+1,sb+1,ta+1,tb+1);
		for(int i=0;i<=n+1;++i){
			cnta[i][0]=cnta[i][1]=cntb[i][0]=cntb[i][1]=0;
			ansa[i]=ansb[i]=-1;
		}
		for(int i=1;i<=n;++i){
			if(ta[i]=='0')ansa[i]=sa[i]-'0';
			if(tb[i]=='0')ansb[i]=sb[i]-'0';
		}
		for(int l=1,r=1;l<=n;l=r+1){
			r=l;
			if(ta[l]=='0')continue;
			while(r<n&&ta[r+1]=='1')++r;
			for(int i=l;i<=r;++i)++cnta[l][sa[i]-'0'];
			for(int i=l;i<=r;++i){
				if(tb[i]=='0'){
					if(cnta[l][sb[i]-'0']){ansa[i]=sb[i]-'0'; --cnta[l][sb[i]-'0'];}
					else{ansa[i]='1'-sb[i]; --cnta[l]['1'-sb[i]];}
				}
			}
		}
		for(int l=1,r=1;l<=n;l=r+1){
			r=l;
			if(tb[l]=='0')continue;
			while(r<n&&tb[r+1]=='1')++r;
			for(int i=l;i<=r;++i)++cntb[l][sb[i]-'0'];
			for(int i=l;i<=r;++i){
				if(ta[i]=='0'){
					if(cntb[l][sa[i]-'0']){ansb[i]=sa[i]-'0'; --cntb[l][sa[i]-'0'];}
					else{ansb[i]='1'-sa[i]; --cntb[l]['1'-sa[i]];}
				}
			}
		}
		int cnta0=0,cnta1=0,cntb0=0,cntb1=0;
		for(int i=1;i<=n;++i){
			cnta0+=cnta[i][0]; cnta1+=cnta[i][1];
			cntb0+=cntb[i][0]; cntb1+=cntb[i][1];
			if(ta[i]=='1'&&tb[i]=='1'){
				if(cnta0&&cntb0){ansa[i]=ansb[i]=0; --cnta0; --cntb0;}
				else if(cnta1&&cntb1){ansa[i]=ansb[i]=1; --cnta1; --cntb1;}
				else{
					if(cnta0){ansa[i]=0; --cnta0;}else{ansa[i]=1; --cnta1;}
					if(cntb0){ansb[i]=0; --cntb0;}else{ansb[i]=1; --cntb1;}
				}
			}
		}
		ans=0;
		for(int i=1;i<=n;++i)if(ansa[i]==ansb[i])++ans;
		printf("%d\n",ans);
	}
	return 0;
}

