#include<bits/stdc++.h>
using namespace std;
int t,n,ans,maxn; 
string s1,s2,t1,t2;
void dfs(int j,string s1,string s2)
{
	if (j == n - 1)
	{
		int tmp = 0;
		for (int i = 0;i < n;i++)
		{
			if (s1[i] == s2[i]) tmp++;
		}
		maxn = max(maxn,tmp);
		return;
	}
	string s3 = s1,s4 = s2;
	if (t1[j] != '0'&&t1[j + 1] != '0')
	{
		swap(s3[j],s3[j + 1]);
		dfs(j + 1,s3,s2);
	}
	if (t2[j] != '0'&&t2[j + 1] != '0')
	{
		swap(s4[j],s4[j + 1]);
		dfs(j + 1,s1,s4);		
	}
	dfs(j + 1,s1,s2);
	dfs(j + 1,s3,s4);
}
int main()
{
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	cin>>t;
	for (int i = 1;i <= t;i++)
	{
		cin>>n;
		cin>>s1>>s2>>t1>>t2;
		if (n <= 10)
		{
			dfs(0,s1,s2);
			cout<<maxn<<endl;
			maxn = 0;
			continue;
		}
		else if(t1 == t2)
		{
			int num1 = 0,num2 = 0,num = 0;
			for (int j = 0;j < n;j++)
			{
				if (t1[j] == '0'&&t2[j] == '0')
				{
					if (s1[j] == s2[j])
					{
						ans++;
					}
					ans = ans + num - abs(num1 - num2);
					num = 0;num1 = 0;num2 = 0;
				}
				else
				{
					if (s1[j] == '1') num1++;
					if (s2[j] == '1') num2++;
					num++;		
				}
			}
			ans = ans + num - abs(num1 - num2);	
			num = 0;num1 = 0;num2 = 0;					
		}
		else
		{
			for (int j = 0;j < n;j++)
			{
				if (s1[j] == s2[j])
				{
					ans++;
				}
			}
		}
		cout<<ans<<endl;
		ans = 0;
	}
	return 0;
}

