#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;

int n,T;
int st1[100005],st2[100005];
int ch1[100005],ch2[100005];
int ans = 0;

void getans()
{
	for(int j = 1;j <= 30;j++) 
	{
		for(int i = 1;i <= n;i++)
		{
			if(st1[i] == st2[i])
			{
				continue;
			}
			if(ch1[i] == 1 && ch1[i + 1] == 1)
				swap(st1[i],st1[i + 1]);
		}
		for(int i = 1;i <= n;i++)
		{
			if(st1[i] == st2[i])
			{
				continue;
			}
			if(ch2[i] == 1 && ch2[i + 1] == 1)
				swap(st2[i],st2[i + 1]); 
		}
		int cnt = 0;
		for(int i = 1;i <= n;i++)
		{
			if(st1[i] == st2[i])
				cnt++;
		}
		ans = max(ans,cnt);
	}
	
	return;
}
int main()
{
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	scanf("%d",&T);
	for(int j = 1;j <= T;j++)
	{
		memset(st1,-1,sizeof(st1)); 
		memset(st2,-1,sizeof(st2)); 
		memset(ch1,-1,sizeof(ch1)); 
		memset(ch2,-1,sizeof(ch2)); 
		ans = 0;
		scanf("%d",&n);
		getchar();
		for(int i = 1;i <= n;i++)
			st1[i] = getchar() - '0';
		getchar();
		for(int i = 1;i <= n;i++)
			st2[i] = getchar() - '0';
		getchar();
		char tmp;
		for(int i = 1;i <= n;i++)
		{
			tmp = getchar();
			if(tmp == '1')
				ch1[i] = 1;
			else
				ch1[i] = 0;
		}
		getchar();
		for(int i = 1;i <= n;i++)
		{
			tmp = getchar();
			if(tmp == '1')
				ch2[i] = 1;
			else
				ch2[i] = 0;
		}
		getans();
		/*for(int i = 1;i <= n;i++)
		{
			if(st1[i] == st2[i])
				ans++;
		}*/
		printf("%d\n",ans);	
	}
	return 0;
} 
