#include<cstdio>
#include<algorithm>
#include<vector>
#include<cmath>
using namespace std;
namespace io{
template<typename T>
void read(T &x)
{
	x=0;
	int f=1;
	char c=getchar();
	while(c<'0'||c>'9')
	{
		if(c=='-')
		{
			f=-1;
		}
		c=getchar();
	}
	while(c>='0'&&c<='9')
	{
		x=(x<<1)+(x<<3)+int(c-'0');
		c=getchar();
	}
	x*=f;
}
template<typename T>
void write(T x)
{
	if(x<0)
	{
		putchar('-');
		x=-x;
	}
	if(x>=10)
	{
		write(x/10);
	}
	putchar('0'+int(x%10));
}}
namespace cyrxdzj{
//#define debug
//#define check_memory
#ifdef check_memory
bool check_memory_st;
#endif
const int MAXN=2e5;
int tccnt;
int n;
char s[2][MAXN+5];
char t[2][MAXN+5];
int stoid[2][MAXN+5];
int storage[MAXN*2+5][2];
int scnt;
int ans;
#ifdef check_memory
bool check_memory_ed;
#endif
int main()
{
	#ifdef check_memory
	printf("check_memory %lf\n",((double)((&check_memory_st)-(&check_memory_ed)))/1024/1024);
	#endif
	freopen("edit.in","r",stdin);
	#ifndef debug
	freopen("edit.out","w",stdout);
	#endif
	scanf("%d",&tccnt);
	while(tccnt--)
	{
		int n;
		scanf("%d",&n);
		ans=0;
		for(int i=1;i<=2*n;i++)
		{
			storage[i][0]=storage[i][1]=0;
		}
		for(int i=0;i<=1;i++)
		{
			scanf("%s",s[i]+1);
			for(int j=1;j<=n;j++)
			{
				stoid[i][j]=0;
			}
		}
		for(int i=0;i<=1;i++)
		{
			scanf("%s",t[i]+1);
		}
		scnt=0;
		for(int sid=0;sid<=1;sid++)
		{
			for(int l=1;l<=n;l++)
			{
				if(t[sid][l]=='0')
				{
					stoid[sid][l]=0;
					continue;
				}
				int r=l;
				while((r+1<=n)&&(t[sid][r+1]=='1'))
				{
					r++;
				}
				scnt++;
				for(int i=l;i<=r;i++)
				{
					stoid[sid][i]=scnt;
					storage[scnt][s[sid][i]-'0']++;
				}
				l=r;
			}
		}
		#ifdef debug
		for(int sid=0;sid<=1;sid++)
		{
			printf("sid %d\n",sid);
			for(int i=1;i<=n;i++)
			{
				printf("%d ",stoid[sid][i]);
			}
			printf("\n");
		}
		printf("storage %d\n",scnt);
		for(int i=1;i<=scnt;i++)
		{
			printf("%d %d\n",storage[i][0],storage[i][1]);
		}
		#endif
		for(int i=1;i<=n;i++)
		{
			if((t[0][i]=='0')&&(t[1][i]=='0'))
			{
				if(s[0][i]==s[1][i])
				{
					ans++;
				}
			}
		}
		for(int i=1;i<=n;i++)
		{
			for(int j=0;j<=1;j++)
			{
				if((t[j][i]=='0')&&(t[j^1][i]=='1'))
				{
					if(storage[stoid[j^1][i]][s[j][i]-'0']>0)
					{
						storage[stoid[j^1][i]][s[j][i]-'0']--;
						ans++;
					}
				}
			}
		}
		for(int i=1;i<=n;i++)
		{
			if((t[0][i]=='1')&&(t[1][i]=='1'))
			{
				for(int j=0;j<=1;j++)
				{
					if((storage[stoid[0][i]][j]>0)&&(storage[stoid[1][i]][j]>0))
					{
						storage[stoid[0][i]][j]--;
						storage[stoid[1][i]][j]--;
						ans++;
						break;
					}
				}
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}}
int main()
{
	return cyrxdzj::main();
}
