#include <bits/stdc++.h>
typedef long long LL;

int read()
{
	int s = 0, f = 1; char c = getchar();
	for (; !isdigit(c); c = getchar()) f ^= (c == '-');
	for (; isdigit(c); c = getchar()) s = s * 10 + (c ^ 48);
	return f ? s : -s;
}
template<typename T> 
void write(T x, char end = '\n')
{
	if (x < 0) x = -x, putchar('-');
	static int d[100], cur = 0;
	do { d[++cur] = x % 10; } while (x /= 10);
	while (cur) putchar('0' + d[cur--]);
	putchar(end);
}
template<typename T> 
void Fmax(T &x, T y){ if (x < y) x = y; }
template<typename T> 
void Fmin(T &x, T y){ if (y < x) x = y; }
const int MAXN = 100005;
int n;
char s[2][MAXN], t[2][MAXN];
void find(int o, int p, int c[])
{
	if (t[o][p] == '0')
	{
		c[0] = c[1] = 0;
		c[s[o][p] - '0'] = 1; return ;
	}
	if (p > 1 && t[o][p - 1] != '0') return ;
	c[0] = c[1] = 0;
	for (int i = p; i <= n && t[o][i] == '1'; i++)
		c[s[o][i] - '0']++;
}
void mian()
{
	n = read();
	scanf("%s %s %s %s", s[0] + 1, s[1] + 1, t[0] + 1, t[1] + 1);
	int cnt[2][2] = {{0, 0}, {0, 0}}, ans = 0;
	for (int i = 1; i <= n; i++)
	{
		for (int o = 0; o <= 1; o++) find(o, i, cnt[o]);
//		printf("%d: (%d,%d) (%d,%d)\n", i, cnt[0][0], cnt[0][1], cnt[1][0], cnt[1][1]);
		if (cnt[0][0] && cnt[1][0]) ans++, cnt[0][0]--, cnt[1][0]--;
		else if (cnt[0][1] && cnt[1][1]) ans++, cnt[0][1]--, cnt[1][1]--;
		else
		{
			for (int o = 0; o <= 1; o++)
				if (cnt[o][0]) cnt[o][0]--;
				else cnt[o][1]--;
		}
	}
	write(ans);
}
int main()
{
	freopen("edit.in", "r", stdin);
	freopen("edit.out", "w", stdout);
	for (int T = read(); T--; ) mian();
	return 0; 
}
