#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL N=1e5+10;
LL T,n,ans,tag[N];
bool vis[N];
char s[N],t[N],tmp[N];
struct seg
{
	LL l,r,c0,c1;
}a[N],b[N];
void Cheems(seg *a,char *s,LL &n1)
{
	scanf("%s",tmp+1);
	for(int i=1,lst=0,cnt0=0,cnt1=0;i<=n;i++)
	{
		cnt0+=(s[i]=='0'),cnt1+=(s[i]=='1');
		if(tmp[i+1]=='0'||i==n||tmp[i]=='0')
		{
			a[++n1]=(seg){lst+1,i,cnt0,cnt1};
			cnt0=cnt1=0; lst=i;
		}
	}
}
bool xinzhiA()
{
	for(int i=1;i<n;i++) if(s[i]!=s[i+1]) return 0;
	return 1; 
}
void solveA()
{
	LL ans=0;
	for(int i=1;i<=n;i++) if(s[i]==t[i]) ans++;
	printf("%lld\n",ans);
}
bool xinzhiB(LL n1,LL n2)
{
	if(n1!=n2) return 0;
	for(int i=1;i<=n1;i++)
		if(a[i].r!=b[i].r) return 0;
	return 1;
}
void solveB(LL n1)
{
	LL ans=0;
	for(int i=1;i<=n1;i++)
		ans+=min(a[i].c0,b[i].c0)+min(a[i].c1,b[i].c1);
	printf("%lld\n",ans);
}
void solve()
{
	LL n1=0,n2=0;
	scanf("%lld%s%s",&n,s+1,t+1);
	Cheems(a,s,n1); Cheems(b,t,n2);
	if(xinzhiA()) return solveA();
	if(xinzhiB(n1,n2)) return solveB(n1);
	LL ans=0;
	for(int i=1,j=1;i<=n1;i++)
	{
		while(j<=n2&&b[j].r<=a[i].r)
		{
			if(b[j].l>=a[i].l)
			{
				LL tk0=min(a[i].c0,b[j].c0);
				LL tk1=min(a[i].c1,b[j].c1);
				ans+=tk0+tk1;
				a[i].c0-=tk0; a[i].c1-=tk1;
				b[j].c0-=tk0; b[j].c1-=tk1;
			}
			else tag[i]=j;
			j++;
		}
	}
	LL tr=0;
	for(int i=1;i<=n1;i++)
	{
		if(!tag[i]) { tr=0; continue; }
		LL res=0,op0=0,op1=0;
		LL lim=b[tag[i]].r-a[i].l+1;
		for(int j=a[i].l;j<=b[tag[i]].r;j++)
		{
			LL trans=j-min(a[i].c1,b[tag[i]].c1);
			if(trans>tr) continue; 
			LL tk0=min(a[i].c0,b[tag[i]].c0+trans),tk1=j;
			if(res<min(lim,tk0+tk1))
			{
				res=min(lim,tk0+tk1);
				op0=tk0; op1=tk1;
			}
		}
		ans+=res;
		tr=op0-(lim-op1);
	}
	printf("%lld\n",ans);
	for(int i=1;i<=n1;i++) tag[i]=0;
}
int main()
{
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	scanf("%lld",&T);
	while(T--) solve();
	return 0;
}
