#include<bits/stdc++.h>
#include<cstdio>
#define ll long long
#define N 200020

using namespace std;

inline ll read()
{
	ll x=0,f=1;
	char ch=getchar();
	while(ch>'9'||ch<'0')
	{
		if(ch=='-')f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9')
	x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	return x*f; 
} 

void write(ll x)
{
	if(x<0)putchar('-'),x=-x;
	if(x>=10)write(x/10);
	putchar(x%10+'0');
}

char s1[N],s2[N];
char t1[N],t2[N];
bool flag1[N],flag2[N];
ll num1[N][2],num2[N][2];
ll n;
ll ans;
ll T;

inline void clear()
{
	memset(num1,0,sizeof(num1));
	memset(num2,0,sizeof(num2));
	memset(flag1,0,sizeof(flag1));
	memset(flag2,0,sizeof(flag2));
	ans=0;
}

inline void init()
{
	n=read();
	scanf("%s",s1+1);
	scanf("%s",s2+1);
	scanf("%s",t1+1);
	scanf("%s",t2+1);
	ll st=0;
	for(ll i=1;i<=n;i++)
	{
		if(t1[i]=='0')
		{
			flag1[i]=1;
			st=i;
		}
		else 
		{
			if(s1[i]=='0')num1[st][0]++;
			else num1[st][1]++; 
		}
	}
	st=0;
	for(ll i=1;i<=n;i++)
	{
		if(t2[i]=='0')
		{
			flag2[i]=1;
			st=i;
		}
		else 
		{
			if(s2[i]=='0')num2[st][0]++;
			else num2[st][1]++; 
		}
	}
}

inline void work()
{
	ll st1=0,st2=0;
	for(ll i=1;i<=n;i++)
	{
		if(flag1[i]&&flag2[i])
		{
			st1=st2=i;
			if(s1[i]==s2[i])ans++;
		}
		else if(flag1[i])
		{
			st1=i;
			if(num2[st2][s1[i]-'0'])
			{
				ans++;
				num2[st2][s1[i]-'0']--;
			}
			else num2[st2][(s1[i]-'0')^1]--;
		}
		else if(flag2[i])
		{
			st2=i;
			if(num1[st1][s2[i]-'0'])
			{
				ans++;
				num1[st1][s2[i]-'0']--;
			}
			else num1[st1][(s2[i]-'0')^1]--;
		}
		else 
		{
			if(num1[st1][0]&&num2[st2][0])
			{
				num1[st1][0]--;
				num2[st2][0]--;
				ans++;
			}
			else if(num1[st1][1]&&num2[st2][1])
			{
				num1[st1][1]--;
				num2[st2][1]--;
				ans++;
			}
			else 
			{
				if(num1[st1][0])num1[st1][0]--;
				else num1[st1][1]--;
				if(num2[st2][0])num2[st2][0]--;
				else num2[st2][1]--;
			}
		}
	}
}

inline void wr()
{
	write(ans);
	putchar('\n');
}

int main()
{
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	T=read();
	while(T--)
	{
		clear();
		init();
		work();
		wr();
	}
	return 0;
}
