#include<bits/stdc++.h>
#define LL long long
#define db double
#define fi first
#define se second
using namespace std;

const int N=1e5+10;

char sa[N],sb[N],ta[N],tb[N];
int n,cnta[2],cntb[2];
int pa[N],ma,pb[N],mb;

void mian()
{
	scanf("%d",&n);
	scanf("%s%s%s%s",sa+1,sb+1,ta+1,tb+1);
	
	for(int i=1; i<=n; i++)
		if(ta[i]=='0') pa[++ma]=i;
	for(int i=1; i<=n; i++)
		if(tb[i]=='0') pb[++mb]=i;
	pa[++ma]=n+1;
	pb[++mb]=n+1;
		
	int tpa=1,tpb=1,la=0,lb=0,ans=0,lst=0;
	while(tpa<=ma || tpb<=mb)
	{
		for(int i=pa[la]+1; i<pa[tpa]; i++)
			cnta[sa[i]-'0']++;
		la=tpa;
		for(int i=pb[lb]+1; i<pb[tpb]; i++)
			cntb[sb[i]-'0']++;
		lb=tpb;
		
		int tmp=0;
		for(int i=0; i<2; i++)
		{
			int cur=0;
//			cout<<cnta[i]<<" "<<cntb[i]<<"\n";
			cur+=min(cnta[i],cntb[i]);
			cur=min(cur,min(pa[tpa]-1,pb[tpb]-1)-lst-tmp);
//			int x=min(cnta[i],cntb[i]);
			cnta[i]-=cur; cntb[i]-=cur;
			ans+=cur; tmp+=cur;
		}
		lst=min(pa[tpa],pb[tpb]);
		
//		cout<<pa[tpa]<<" "<<pb[tpb]<<" "<<ans<<"\n";
		
		if(pa[tpa]<pb[tpb])
		{
			if(tpa<ma)
			{
				int x=(sa[pa[tpa]]-'0');
				if(cntb[x]) cntb[x]--, ans++;
			}
			tpa++;	
			for(int i=0; i<2; i++)
				cnta[i]=0;
		} 
		else if(pa[tpa]>pb[tpb])
		{
			if(tpb<mb)
			{
				int x=(sb[pb[tpb]]-'0');
				if(cnta[x]) cnta[x]--, ans++;
			}
			tpb++;
			for(int i=0; i<2; i++)
				cntb[i]=0;	
		} 
		else
		{
			if(tpa<ma && tpb<mb)
			{
				if(sa[pa[tpa]]==sb[pb[tpb]]) ans++;	
			}
			tpa++; tpb++;
			for(int i=0; i<2; i++)
				cnta[i]=cntb[i]=0;	
		}
//		cout<<ans<<"\n";
	} 
	
	printf("%d\n",ans);
	for(int i=0; i<2; i++)
		cnta[i]=cntb[i]=0;
	ma=mb=0;
}

int main()
{
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);

	int T; scanf("%d",&T);
	while(T--) mian();

	return 0;
}

