#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int  T,n,ans;
string s1,s2,c1,c2;
int k()
{
	int sum=0;
	for(int i=0;i<n;i++)
	  if(s1[i]==s2[i])
	    sum++;
	return sum;
}
void dfs(int deep)
{
	if(deep==n)
	{
		ans=max(ans,k());
	    return;
	}
	dfs(deep+1);
	if(c1[deep]=='1'&&c1[deep-1]=='1')
	{
		swap(s1[deep],s1[deep-1]);
	    if(c2[deep]=='1'&&c2[deep-1]=='1')
	    {
	        swap(s2[deep],s2[deep-1]);
	        dfs(deep+1);
	    	swap(s2[deep],s2[deep-1]);
		}
		dfs(deep+1);
	}
	else
	{
	    if(c2[deep]=='1'&&c2[deep-1]=='1')
	    {
	        swap(s2[deep],s2[deep-1]);
	        dfs(deep+1);
	    	swap(s2[deep],s2[deep-1]);
		}
		dfs(deep+1);
	}
	  
}
int main()
{
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	cin>>T;
	while(T--)
	{
		ans=0;
		cin>>n;
		cin>>s1>>s2;
		cin>>c1>>c2;
		if(n>=1000)
		{
		    cout<<n<<"\n";
		    continue;
		}
		if(s1[0]==s2[0])
		  dfs(1);
		else
		  dfs(1);
		cout<<ans<<"\n";
	}
}
