#include<bits/stdc++.h>
#define ll long long
#define mp(a,b) make_pair(a,b)
using namespace std;
const ll MAXN=1e5+5;
ll T,n,L1,L2;
char s1[MAXN],s2[MAXN],t1[MAXN],t2[MAXN];
struct node
{
	ll L,R,sum0,sum1;
}Len1[MAXN],Len2[MAXN];
void init()
{
	L1=L2=0;
	for(ll i=1;i<=n;i++)
		if(i==1||t1[i]=='0'||t1[i-1]=='0')
		{
			L1++;
			Len1[L1].L=Len1[L1].R=i;
			if(s1[i]=='0') Len1[L1].sum0=1,Len1[L1].sum1=0;
			else Len1[L1].sum0=0,Len1[L1].sum1=1;
		}
		else
		{
			Len1[L1].R=i;
			if(s1[i]=='0') Len1[L1].sum0++;
			else Len1[L1].sum1++;
		}
	for(ll i=1;i<=n;i++)
		if(i==1||t2[i]=='0'||t2[i-1]=='0')
		{
			L2++;
			Len2[L2].L=Len2[L2].R=i;
			if(s2[i]=='0') Len2[L2].sum0=1,Len2[L2].sum1=0;
			else Len2[L2].sum0=0,Len2[L2].sum1=1;
		}
		else
		{
			Len2[L2].R=i;
			if(s2[i]=='0') Len2[L2].sum0++;
			else Len2[L2].sum1++;
		}
}
ll LEN(ll L1,ll R1,ll L2,ll R2)
{
	return min(R2-L1+1,R1-L2+1);
}
int main()
{
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	scanf("%lld",&T);
	while(T--)
	{
		scanf("%lld%s%s%s%s",&n,s1+1,s2+1,t1+1,t2+1);
		init();
		ll ans=0;
		for(ll i=1,j=1;i<=L1;i++)
		{
			while(j<=L2)
			{
				ll t=LEN(Len1[i].L,Len1[i].R,Len2[j].L,Len2[j].R);
				ll Max0=min(min(Len1[i].sum0,Len2[j].sum0),t);
				Len1[i].sum0-=Max0,Len2[j].sum0-=Max0,t-=Max0,ans+=Max0;
				ll Max1=min(min(Len1[i].sum1,Len2[j].sum1),t);
				Len1[i].sum1-=Max1,Len2[j].sum1-=Max1,t-=Max1,ans+=Max1;
				if(Len1[i].R<=Len2[j].R)
				{
					if(Len1[i].sum0) Len2[j].sum1-=Len1[i].sum0,Len1[i].sum0=0;
					if(Len1[i].sum1) Len2[j].sum0-=Len1[i].sum1,Len1[i].sum1=0;
				}
				else
				{
					if(Len2[j].sum0) Len1[i].sum1-=Len2[j].sum0,Len2[j].sum0=0;
					if(Len2[j].sum1) Len1[i].sum0-=Len2[j].sum1,Len2[j].sum1=0;
				}
				if(Len1[i].R==Len2[j].R)
				{
					j++;
					break;
				}
				if(Len1[i].R<Len2[j].R) break;
				j++;
			}
		}
		printf("%lld\n",ans);
	}
	return 0;
}
