#include<bits/stdc++.h>
#define ci const int
using namespace std;
ci N=1e5+5;
int n,al[N][2],ar[N][2];
char s1[N],s2[N],t1[N],t2[N];
void Init(){
	for(int i=1;i<=n;++i)al[i][0]=al[i][1]=ar[i][0]=ar[i][1]=0;
}
void Work(){
	scanf("%d%s%s%s%s",&n,s1+1,s2+1,t1+1,t2+1);
	for(int i=1,pos=1;i<=n;++i){
		if(t1[i]=='0'||t1[i-1]=='0')pos=i;
		if(s1[i]=='0')++al[pos][0];
		else ++al[pos][1];
	}
	for(int i=1,pos=1;i<=n;++i){
		if(t2[i]=='0'||t2[i-1]=='0')pos=i;
		if(s2[i]=='0')++ar[pos][0];
		else ++ar[pos][1];
	}
	int ans=0,cntl0=0,cntl1=0,cntr0=0,cntr1=0;
	for(int i=1;i<=n;++i){
		cntl0+=al[i][0],cntl1+=al[i][1],
		cntr0+=ar[i][0],cntr1+=ar[i][1];
		if(cntl0&&cntr0)++ans,--cntl0,--cntr0;
		else if(cntl1&&cntr1)++ans,--cntl1,--cntr1;
		else{
			if(cntl0)--cntl0;
			else --cntl1;
			if(cntr0)--cntr0;
			else --cntr1;
		}
	}
	printf("%d\n",ans);
}
int main(){
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	int T;scanf("%d",&T);
	while(T--)Work(),Init();
	return 0;
}