#include <bits/stdc++.h>

using namespace std;
const int maxn = 100004;
char str[2][maxn], tp[2][maxn];
int t, n;

void solve()
{
	//if(n==997)cout<<str[0]<<endl<<str[1]<<endl;
	for(int i=0;i<n;i++)
	{
		int cur = 0;
		//printf("\n%d: %c-%c ", i, str[0][i], str[1][i]);
		if(tp[cur][i] == '0') continue;
		if(str[0][i] == str[1][i]) continue;
		//printf("[%d, %c == %c]\n", i, str[0][i], str[1][i]);
		//printf("<%d>", i);
		int opt = 0, fj = 0;
		for(int j=i+1;j<n;j++)
		{
			if(tp[cur][j] == '0') continue;
			if(str[cur][i] == str[cur][j]) opt=1, fj=(fj==0)?j:fj;
			if(str[cur][i] != str[cur][j]) swap(str[cur][i], str[cur][j]);
			//printf("%d swap with %d\n", i, j);
			break;
		}
		if(opt) swap(str[cur][i], str[cur][fj]);
	}
	for(int i=0;i<n;i++)
	{
		int cur = 1;
		if(tp[cur][i] == '0') continue;
		if(str[0][i] == str[1][i]) continue;
		int opt = 0, fj = 0;
		for(int j=i+1;j<n;j++)
		{
			if(tp[cur][j] == '0') continue;
			if(str[cur][i] == str[cur][j]) opt=1, fj=(fj==0)?j:fj;
			if(str[cur][i] != str[cur][j]) swap(str[cur][i], str[cur][j]);
			break;
		}
		if(opt) swap(str[cur][i], str[cur][fj]);
	}
	//cout<<"str1 = "<<str[0]<<endl<<"str2 = "<<str[1]<<endl;
	int cnt = 0;
	for(int i=0;i<n;i++) cnt += str[0][i] == str[1][i];
	printf("%d\n", cnt);
}

int main()
{
	freopen("edit.in", "r", stdin);
	freopen("edit.out", "w", stdout);
	scanf("%d", &t);
	while(t--)
	{
		scanf("%d", &n);
		scanf("%s%s%s%s", str[0], str[1], tp[0], tp[1]);
		solve();
	}
	return 0;
}

