#include<bits/stdc++.h>
using namespace std;
#define int long long
#define f(i,j,k) for(int i=j;i<=k;++i)
#define g(i,j,k) for(int i=j;i>=k;--i)
int n,m,s,l;
inline int read(){
	int x=0,f=1;char ch=getchar();
	for(;'0'>ch||ch>'9';ch=getchar())if(ch=='-')f=-f;
	for(;'0'<=ch&&ch<='9';ch=getchar())x=(x<<3)+(x<<1)+(ch^48);
	return x*f; 
}
void write(int x){if(x>9)write(x/10);putchar(x%10+48);}
const int N=2e5;
char a[N],b[N],pa[N],pb[N];
int a0,a1,b0,b1;
inline void ck(char*a,char*p,int&a0,int&a1,int i){
	if(p[i]=='0'){
		a0=a[i]=='0';
		a1=a[i]=='1'; 
	}else if(p[i-1]=='0'){
		for(a0=a1=0;p[i]=='1';++i)a[i]=='0'?++a0:++a1;
	}
}
inline void doing(){
	n=read();
	scanf("%s",a+1);
	scanf("%s",b+1);
	scanf("%s",pa+1);
	scanf("%s",pb+1);
	pa[0]=pb[0]=pa[n+1]=pb[n+1]='0';
	m=a0=a1=b0=b1=0;
	f(i,1,n){
		ck(a,pa,a0,a1,i);
		ck(b,pb,b0,b1,i);
		if(a0&&b0){
			++m;--a0;--b0;
		}else if(a1&&b1){
			++m;--a1;--b1;
		}else if(a0&&b1){
			--a0;--b1;
		}else if(a1&&b0){
			--a1;--b0;
		}else{
			assert(0);
		}
	}
	printf("%lld\n",m);
}
signed main(){
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	int t=read();
	while(t--)doing(); 
	return 0;
}
