#include<bits/stdc++.h>
using namespace std;
namespace IO{
	void read(int &x){
		short f=1;x=0;char ch=getchar();
		while(ch<'0'||ch>'9'){if(ch=='-') f=-1;ch=getchar();}
		while(ch>='0'&&ch<='9') x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
		x*=f;
		return;
	}
	void out(int x){
		if(x<0) putchar('-'),x=-x;
		if(x>9) out(x/10);
		putchar(x%10+'0');
		return;
	}
	void endl(){
		putchar('\n');
		return;
	}
}
using IO::read;
using IO::out;
using IO::endl;
const int N=1e6+5;
int T,n;
char s1[N],s2[N];
char t1[N],t2[N];
int num1[N],num2[N],num3[N],num4[N],pre1[N],pre2[N];
void move(int &x,int &y,int &z,int d){
	int tmp=min(x,y);
	tmp=min(tmp,d);
	x-=tmp,y-=tmp,z+=tmp; 
	return;
}
signed main(){
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	read(T);
	while(T--){
		read(n);
		scanf("%s%s%s%s",s1+1,s2+1,t1+1,t2+1);
		for(int i=1;i<=n;i++){
			pre1[i]=pre2[i]=num1[i]=num2[i]=num3[i]=num4[i]=0;
		}
		for(int i=1;i<=n;i++){
			if(i!=1&&t1[i-1]=='1') pre1[i]=pre1[i-1];
			else pre1[i]=i;
			if(i!=1&&t2[i-1]=='1') pre2[i]=pre2[i-1];
			else pre2[i]=i;
		}
		for(int i=1;i<=n;i++){
			if(t1[i]=='1'){
				if(s1[i]=='0') num1[pre1[i]]++;
				else num2[pre1[i]]++;
			}
			if(t2[i]=='1'){
				if(s2[i]=='0') num3[pre2[i]]++;
				else num4[pre2[i]]++;
			}
		}
		int ans=0,ls=0,pos=1;
		while(true){
			while(pos<=n&&t1[pos]=='1'&&t2[pos]=='1') pos++;
			if(ls!=0){
				if(t1[ls]=='0'&&t2[ls]=='1'){
					if(s1[ls]=='0'){
						if(num3[pre2[ls]]) num3[pre2[ls]]--,ans++;
					}
					else{
						if(num4[pre2[ls]]) num4[pre2[ls]]--,ans++;
					}
				}
				else if(t1[ls]=='1'&&t2[ls]=='0'){
					if(s2[ls]=='0'){
						if(num1[pre1[ls]]) num1[pre1[ls]]--,ans++;
					}
					else{
						if(num2[pre1[ls]]) num2[pre1[ls]]--,ans++;
					}
				}
				else if(s1[ls]==s2[ls]) ans++;
			}
			if(ls+1<pos){
				move(num1[pre1[ls+1]],num3[pre2[ls+1]],ans,pos-ls-1);
				move(num2[pre1[ls+1]],num4[pre2[ls+1]],ans,pos-ls-1);
			}
			ls=pos,pos++;
			if(ls>n) break;
		}
		out(ans),endl();
	}
	return 0;
}
