#include<bits/stdc++.h>
#define pb push_back
#define P make_pair
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define fi first
#define se second
using namespace std;
typedef long long ll;
inline ll read(){
	ll x=0;char c=getchar();
	while(c<'0'||c>'9')c=getchar();
	while(c>='0'&&c<='9')x=x*10+c-'0',c=getchar();
	return x;
}
const int N=1e5+3;
int n;
char a[N],b[N],ta[N],tb[N];
int c[N],d[N],n1,n2;
inline void solve(){
	scanf("%d%s%s%s%s",&n,a+1,b+1,ta+1,tb+1);
	n1=n2=0;
	rep(i,1,n)if(ta[i]=='0')c[++n1]=i;
	rep(i,1,n)if(tb[i]=='0')d[++n2]=i;
	c[++n1]=n+1,d[++n2]=n+1;
	int ans=0;
	int ca[2]={0,0},cb[2]={0,0};
	rep(i,1,c[1]-1)++ca[a[i]&1];
	rep(i,1,d[1]-1)++cb[b[i]&1];
	for(int i=1,j=1;i<=n1&&j<=n2;){
		rep(d,0,1){
			int k=min(ca[d],cb[d]);
			ans+=k,ca[d]-=k,cb[d]-=k;
		}
		if(c[i]==d[j]){
			if(i==n1&&j==n2)break;
			ans += a[c[i]]==b[d[j]];
			rep(d,0,1)ca[d]=cb[d]=0;
			rep(k,c[i]+1,c[i+1]-1)++ca[a[k]&1];
			rep(k,d[j]+1,d[j+1]-1)++cb[b[k]&1];
			++i,++j;
		}
		else if (c[i]<d[j]){
			bool d=a[c[i]]&1;
			if(cb[d])++ans,--cb[d];
			else --cb[d^1];
			rep(d,0,1)if(ca[d])cb[d^1]-=ca[d],ca[d]=0;
			rep(k,c[i]+1,c[i+1]-1)++ca[a[k]&1];
			++i;
		}
		else{
			bool D=b[d[j]]&1;
			if(ca[D])++ans,--ca[D];
			else --ca[D^1];
			rep(d,0,1)if(cb[d])ca[d^1]-=cb[d],cb[d]=0;
			rep(k,d[j]+1,d[j+1]-1)++cb[b[k]&1];
			++j;
		}
	}
	printf("%d\n",ans);
}
int main(){
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	int T=read();while(T--)solve();
	return 0;
}
