#include<bits/stdc++.h>
#define LL long long
#define rep(i,a,b,g) for(LL i=a;i<=b;i+=g)
using namespace std;
LL n;
char a[100010],b[100010],ca[100010],cb[100010];
LL sum,oa,ob;
set<LL>fa[100010],fb[100010];
LL bela[100010],belb[100010],fal[100010],far[100010],fbl[100010],fbr[100010];
LL ffa[100010][3],ffb[100010][3];
mt19937 myrand(time(0));
void sol()
{
	cin>>n>>(a+1)>>(b+1)>>(ca+1)>>(cb+1);
//	rep(i,1,n,1)
//	{
//		if(ca[i]=='1')
//		{
//			if(i==1)
//			{
//				if(ca[2]=='0')ca[1]='0';
//				continue;
//			}
//			if(i==n)
//			{
//				if(ca[n-1]=='0')ca[n]='0';
//				continue;
//			}
//			if(ca[i-1]=='0'&&ca[i+1]=='0')
//			{
//				ca[i]='0';
//			}
//		}
//	}
//	rep(i,1,n,1)
//	{
//		if(cb[i]=='1')
//		{
//			if(i==1)
//			{
//				if(cb[2]=='0')cb[1]='0';
//				continue;
//			}
//			if(i==n)
//			{
//				if(cb[n-1]=='0')cb[n]='0';
//				continue;
//			}
//			if(cb[i-1]=='0'&&cb[i+1]=='0')
//			{
//				cb[i]='0';
//			}
//		}
//	}
	oa=ob=0;
	rep(i,1,n,1)
	{
		fa[i].clear();
		fb[i].clear();
		bela[i]=belb[i]=0;
		ffa[i][0]=ffb[i][0]=0;
		ffa[i][1]=ffb[i][1]=0;
		fal[i]=fbl[i]=far[i]=fbr[i]=0;
	}
	sum=0;
	rep(i,1,n,1)
	{
		if(ca[i]=='0'&&cb[i]=='0')
		{
			sum+=(a[i]==b[i]);
		}
		if(ca[i]=='1')
		{
			if(ca[i-1]=='0'||i==1)oa++;
			fa[oa].insert(i);
			bela[i]=oa;
			ffa[oa][a[i]-'0']++;
		}
		if(cb[i]=='1')
		{
			if(cb[i-1]=='0'||i==1)ob++;
			fb[ob].insert(i);
			belb[i]=ob;
			ffb[ob][b[i]-'0']++;
		}
	}
	rep(i,1,oa,1)
	{
		LL l=*fa[i].begin();
		auto tr=fa[i].end();
		tr--;
		LL r=*tr;
		fal[i]=l;
		far[i]=r;
		rep(j,l,r,1)
		{
			if(cb[j]=='0')
			{
				if(ffa[i][b[j]-'0'])
				{
					ffa[i][b[j]-'0']--;
					sum++;
				}
			}
		}
	}
	rep(i,1,ob,1)
	{
		LL l=*fb[i].begin();
		auto tr=fb[i].end();
		tr--;
		LL r=*tr;
		fbl[i]=l;
		fbr[i]=r;
		rep(j,l,r,1)
		{
			if(ca[j]=='0')
			{
				if(ffb[i][a[j]-'0'])
				{
					ffb[i][a[j]-'0']--;
					sum++;
				}
			}
		}
	}
	LL l,r;
	l=r=0;
	rep(i,1,oa,1)
	{
		while(fbr[l]<fal[i]&&l<=ob)l++;
		while(fbl[r]<=far[i]&&r<=ob)r++;
		r--;
		rep(j,l,r,1)
		{
//			cout<<i<<"<->"<<j<<endl;
			LL ta0=ffa[i][0];
			LL ta1=ffa[i][1];
			LL tb0=ffb[j][0];
			LL tb1=ffb[j][1];
//			cout<<"ta0:"<<ta0<<endl;
//			cout<<"ta1:"<<ta1<<endl;
//			cout<<"tb0:"<<tb0<<endl;
//			cout<<"tb1:"<<tb1<<endl;
			LL tm0=min(ta0,tb0);
			LL tm1=min(ta1,tb1);
//			cout<<"tm0:"<<tm0<<endl;
//			cout<<"tm1:"<<tm1<<endl;
			LL CGj=0;
			LL al=fal[i];
			LL ar=far[i];
			LL bl=fbl[j];
			LL br=fbr[j];
			if(al<=bl&&ar>=br)CGj=br-bl+1;
			if(al>bl&&ar>=br)CGj=br-al+1;
			if(al<=bl&&ar<br)CGj=ar-bl+1;
			if(al>bl&&ar<br)CGj=ar-al+1;
			LL tt=min(tm0+tm1,CGj);
			sum+=tt;
			if(tt==tm0+tm1)
			{
				ffa[i][0]-=tm0;
				ffb[j][0]-=tm0;
				ffa[i][1]-=tm1;
				ffb[j][1]-=tm1;
			}
			else
			{
				if(tt>=tm0)
				{
					ffa[i][0]-=tm0;
					ffb[j][0]-=tm0;
					tt-=tm0;
					ffa[i][1]-=tt;
					ffb[j][1]-=tt;
					continue;
				}
				if(tt>=tm1)
				{
					ffa[i][1]-=tm1;
					ffb[j][1]-=tm1;
					tt-=tm1;
					ffa[i][0]-=tt;
					ffb[j][0]-=tt;
					continue;
				}
				LL ttt=myrand()%2;
				ffa[i][ttt]-=tt;
				ffb[j][ttt]-=tt;
			}
		}
	}
	printf("%lld\n",sum);
}
int main()
{
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	LL T;
	scanf("%lld",&T);
	while(T--)sol();
	return 0;
}
/*
8:30 start coding
8:57 small yangli AC
9:30 know big yangli zuofa
9:47 find bug
10:00 big yangli almost AC
10:15 find bug
10:19 bug fixed still WA
10:28 find new bug
10:31 how?
10:44 think of suijihua, tryed
10:45 AC dayangli!!!
10:53 go to next timu
*/
/*
almost AFO
i only know how to T1 and it don't AC big yangli(10:07)
so got 2= or 3=
bye everyone

oh, and i am 678881 in luogu

my classmates played yuanqiqishi last night until 12:00 and i fuxi to 10:45
he may get 200+, and i got 100-
i'm such a loser

but i'm happy that i met such good friends in OI

i want to say that:
what can i say!
man!
CCNU!

rp++rp++rp++rp++rp++rp++rp++rp++rp++rp++rp++rp++rp++rp++rp++rp++rp++rp++rp++rp++rp++rp++rp++rp++rp++rp++rp++rp++rp++rp++rp++rp++

suijihua don't fail me now

suijihua wo ai ni
suijihua wo ai ni
suijihua wo ai ni
suijihua wo ai ni
suijihua wo ai ni
suijihua wo ai ni
suijihua wo ai ni
suijihua wo ai ni
suijihua wo ai ni
suijihua wo ai ni
suijihua wo ai ni
suijihua wo ai ni
suijihua wo ai ni
suijihua wo ai ni
suijihua wo ai ni
suijihua wo ai ni
suijihua wo ai ni
suijihua wo ai ni
suijihua wo ai ni
suijihua wo ai ni
suijihua wo ai ni
suijihua wo ai ni
suijihua wo ai ni

ohhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh

please give me 100 then i can get 2=!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

if i can get 100 then i won't AFO!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

follooooooooooow me!
me:dzd is love!
you:dzd is love!!
me:dzd is power!
you:dzd is power!!

oh i almost forgot sth.

if you are zhengli-ing daimamihuoxingwei, sixin me and i will tell you if you can put it in your article
*/
