#include<cstdio>
#include<iostream>
#include<algorithm>
#define max(a,b) a>b?a:b
#define min(a,b) a<b?a:b
using namespace std;
const int N=1e5+10;
int n;
char s1[N],s2[N],t1[N],t2[N];
int Ind1,Ind2;
int query1[N],query2[N];
int main()
{
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	int T;scanf("%d",&T);
	while(T--)
	{
		Ind1=0,Ind2=0;
		scanf("%d",&n);
		scanf("%s %s %s %s",s1+1,s2+1,t1+1,t2+1);
		for(int i=1;i<=n;i++)
		{
			if(t1[i]=='0') query1[++Ind1]=i;
			if(t2[i]=='0') query2[++Ind2]=i;
		}
		query2[++Ind2]=n+1;
		query1[++Ind1]=n+1;
		int i=1,j=1;
		while(i<=Ind1&&j<=Ind2)
		{
			int l1=query1[i-1],r1=query1[i],l2=query2[j-1],r2=query2[j];
			if(r1<=r2)
			{
				bool if_0=true,if_1=true;
				++i;
				if(l1>l2)
				{
					for(int k=l1;k<=r1;k++)
					{
						int d=k;
						while(s1[k]!=s2[d]&&d<(r2-1)) ++d;
						swap(s2[d],s2[k]);
					}
				}
				else
				{
					for(int k=l2+1;k<=r1;k++)
					{
						int d=k;
						while(s1[k]!=s2[d]&&d<(r2-1)) ++d;
						swap(s2[d],s2[k]);
					}
				}
			}
			else
			{
				++j;
				if(l1>=l2)
				{
					for(int k=l1+1;k<=r2;k++)
					{
						int d=k;
						while(s1[d]!=s2[k]&&d<(r1-1)) ++d;
						swap(s1[d],s1[k]);
					}
				}
				else
				{
					for(int k=l2;k<=r2;k++)
					{
						int d=k;
						while(s1[d]!=s2[k]&&d<(r1-1)) ++d;
						swap(s1[d],s1[k]);
					}
				}
			}
		}
		int ans=0;
		for(int i=1;i<=n;i++) ans+=(s1[i]==s2[i]);
		printf("%d\n",ans);
	}
}
