#include<cstdio>
#include<algorithm>
using namespace std;
const int maxn = 1e5 + 5;
char s1[maxn], s2[maxn], _f1[maxn], _f2[maxn];
bool f1[maxn], f2[maxn];
int qian1[maxn], qian2[maxn];
int n, ans = 0;

int cnt()
{
	int ans = 0;
	for(int i = 1; i <= n; i ++)
	{
		if(s1[i] == s2[i])
			ans ++;
	}
	return ans;
}

void work()
{
	ans = 0;
	scanf("%d", &n);
	scanf("%s", s1 + 1);
	scanf("%s", s2 + 1);
	scanf("%s", _f1 + 1);
	scanf("%s", _f2 + 1);
	for(int i = 1; i <= n; i++)
	{
		f1[i] = _f1[i] - '0';
		f2[i] = _f2[i] - '0';
	}
	bool flag = 1;
	
	//A
	for(int i = 1; i < n; i ++ )
	{
		if(s1[i] != s1[i + 1])
		{
			flag = 0;
			break;
		}
	}
	if(flag)
	{
		int ans = 0;
		for(int i = 1; i <= n; i ++ )
			if(s2[i] == s1[1])
				ans ++ ;
		printf("%d\n", ans);
		return ; 
	}
	
	//B
	flag = 1;
	for(int i = 1; i <= n; i++)
	{
		if(s1[i] != s2[i])
		{
			flag = 0;
			break;
		}
	}
	if(flag)
	{
		printf("%d\n", n);
		return; 
	}
	
	//C
	flag = 1;
	int s10 = 0, s20 = 0, a1 = 0, a2 = 0;
	for(int i = 1; i <= n; i ++ )
	{
		if(s1[i] == '0')
			s10 ++, a1 = i;
		if(s2[i] == '0')
			s20 ++, a2 = i;
		qian1[i] = qian1[i - 1] + (!f1[i]);
		qian2[i] = qian2[i - 1] + (!f2[i]);
	}
	if(s10 == 1 && s20 == 1)
	{
		int ans;
		if(a1 == a2)
			ans = n;
		else
		{
			if(a1 > a2)
			{
				if(qian1[a1] - qian1[a2 - 1] == 0 || qian2[a1] - qian2[a2 - 1] == 0)
					ans = n;
				else
					ans = n - 2;
			}
			else
			{
				if(qian1[a2] - qian1[a1 - 1] == 0 || qian2[a2] - qian2[a1 - 1] == 0)
					ans = n;
				else
					ans = n - 2;
			}
		}
		printf("%d\n", ans);
		return;
	}
	
	//SA
	double T = 100000.;
	while(T > 0.001)
	{
		int x = rand()% n + 1, y = rand()% n + 1, z = rand()%2;
		if(z)
		{
			if(f1[x] != 0 && f1[x + 1] != 0)
				swap(s1[x], s1[x + 1]);
		}
		else
		{
			if(f2[y] != 0 && f2[y + 1] != 0)
				swap(s2[y], s2[y + 1]);
		}
		ans = max(ans, cnt());
		T *= 0.99;
	}
	printf("%d\n", ans);
	return;
}

int main()
{
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	int t;
	scanf("%d", &t);
	while(t--)
		work(); 
	return 0;
}
