#include<cstdio>
#include<algorithm>
#define N 100010
using namespace std;
int n, na[N], nb[N], ca[N], cb[N];
int tota, totb;
struct node
{
	int en, n[2];
}pa[N], pb[N];
int read()
{
	char c = getchar();
	while(c != '0' && c != '1')c = getchar();
	return c - '0';
}
void slove()
{
	scanf("%d", &n);
	for(int i = 1; i <= n; i++)na[i] = read();
	for(int i = 1; i <= n; i++)nb[i] = read();
	for(int i = 1; i <= n; i++)ca[i] = read()^1;
	for(int i = 1; i <= n; i++)cb[i] = read()^1;
	for(int i = 1; i <= n + 1; i++)pa[i].n[0] = pa[i].n[1] = pa[i].en = 0;
	for(int i = 1; i <= n + 1; i++)pb[i].n[0] = pb[i].n[1] = pb[i].en = 0;
	tota = 0;
	totb = 0;
	na[n + 1] = 0;
	nb[n + 1] = 1;
	ca[n + 1] = cb[n + 1] = 1;
	for(int i = 1; i <= n + 1; i++)
	{
		tota++;
		int j = i;
		while(!ca[j])pa[tota].n[na[j++]]++;
		pa[tota].en = j;
		i = j;
	}
	for(int i = 1; i <= n + 1; i++)
	{
		totb++;
		int j = i;
		while(!cb[j])pb[totb].n[nb[j++]]++;
		pb[totb].en = j;
		i = j;
	}
	int nowa = 1, nowb = 1, ans = 0;
	while(nowa <= tota)
	{
//		printf("%d %d\n", nowa, nowb);
		if(pa[nowa].en == pb[nowb].en)
		{
			ans += (na[pa[nowa].en] == nb[pb[nowb].en]);
			ans += min(pa[nowa].n[0], pb[nowb].n[0]);
			ans += min(pa[nowa].n[1], pb[nowb].n[1]);
			nowa++;
			nowb++;
		}
		else if(pa[nowa].en < pb[nowb].en)
		{
			pa[nowa].n[na[pa[nowa].en]]++;
			int sum0 = min(pa[nowa].n[0], pb[nowb].n[0]), sum1 = min(pb[nowb].n[1], pa[nowa].n[1]);
			ans += sum0 + sum1;
			pb[nowb].n[0] -= sum0;
			pb[nowb].n[1] -= sum1;
			int all = pa[nowa].n[0] + pa[nowa].n[1] - sum0 - sum1;
			if(pb[nowb].n[0])pb[nowb].n[0] -= all;
			else pb[nowb].n[1] -= all;
			nowa++;
		}
		else
		{
			pb[nowb].n[nb[pb[nowb].en]]++;
			int sum0 = min(pb[nowb].n[0], pa[nowa].n[0]), sum1 = min(pa[nowa].n[1], pb[nowb].n[1]);
			ans += sum0 + sum1;
			pa[nowa].n[0] -= sum0;
			pa[nowa].n[1] -= sum1;
			int all = pb[nowb].n[0] + pb[nowb].n[1] - sum0 - sum1;
			if(pa[nowa].n[0])pa[nowa].n[0] -= all;
			else pa[nowa].n[1] -= all;
			nowb++;
		}
	}
	printf("%d\n", ans);
}
int main()
{
	freopen("edit.in", "r", stdin);
	freopen("edit.out", "w", stdout);
	int t;
	scanf("%d", &t);
	while(t--)slove();
	return 0;
}
