#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
const int N=1e5+5;
int a[N],b[N],n,bac1[N],bac2[N];
bool pos1[N],pos2[N];
char s1[N],s2[N],cut1[N],cut2[N];
int main()
{
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	int t;
	cin>>t;
	while(t--)
	{
	int ans=0;
	scanf("%d",&n);
	scanf("%s",s1+1);
	scanf("%s",s2+1);
	scanf("%s",cut1+1);
	scanf("%s",cut2+1);
	pos1[n+1]=pos2[n+1]=0;
	for(int i=1;i<=n;i++)
	{
		a[i]=s1[i]-'0';
		b[i]=s2[i]-'0';
		pos1[i]=cut1[i]-'0';
		pos2[i]=cut2[i]-'0';
	}
	int last=0;
	for(int i=1;i<=n+1;i++)
	{
		if(!pos1[i]&&last+1<=i)
		{
			sort(a+last+1,a+i);
			last=i;
		}
	}
	last=0;
	for(int i=1;i<=n+1;i++)
	{
		if(!pos2[i]&&last+1<=i)
		{
			sort(b+last+1,b+i);
			last=i;
		}
	}
	last=n+1;
	for(int i=n;i>=1;i--)
	{
		if(pos1[i]==0)
			last=i;
		bac1[i]=last;
	}
	last=n+1;
	for(int i=n;i>=1;i--)
	{
		if(pos2[i]==0)
			last=i;
		bac2[i]=last;
	}
	int last1=1,last2=1;
	a[n+1]=1;
	b[n+1]=1;
//	cout<<endl;
//	for(int i=1;i<=n;i++)
//	{
//		cout<<a[i];
//	}
////	cout<<endl;
////	for(int i=1;i<=n;i++)
////	{
////		cout<<bac2[i];
////	}
////	cout<<endl;
	for(int i=1;i<=n;i++)
	{
		last1=max(last1,i+1);
		last2=max(last2,i+1);
		while(!a[last1])
		{
			last1++;
		}
		while(!b[last2])
		{
			last2++;
		}
//		cout<<i<<" "<<last1<<" "<<last2<<endl;
		if(a[i]==b[i])
		{
			ans++;
		}
		else
		{
			if(a[i]==0)
			{
//				cout<<"aaa";
				if(pos1[last1]==1&&last1<=n&&last1<bac1[i])
				{
					swap(a[last1],a[i]);
					last1++;
				ans++;
				}
			}
			else
			{
				if(pos2[last2]==1&&last2<=n&&last2<bac2[i])
				{
					swap(b[last2],b[i]);
					last2++;
				ans++;
				}
			}
		}
	}
	cout<<ans<<endl;
	}
	return 0;
}
