#include <bits/stdc++.h>
#define fst first
#define scd second
#define pb emplace_back
#define mkp make_pair
#define uint unsigned
#define mems(a, x) memset((a), (x), sizeof(a))

using namespace std;
typedef long long ll;
typedef double db;
typedef long double ldb;
typedef unsigned long long ull;
typedef pair<int, int> pii;

const int maxn = 100100;

int n, f[maxn], g[maxn];
pii c[maxn], d[maxn];
char s[maxn], t[maxn], a[maxn], b[maxn];

void solve() {
	scanf("%d%s%s%s%s", &n, s + 1, t + 1, a + 1, b + 1);
	for (int i = 1; i <= n; ++i) {
		f[i] = g[i] = 0;
	}
	int m1 = 0, m2 = 0;
	for (int i = 1, j = 1; i <= n; i = (++j)) {
		if (a[i] == '0') {
			continue;
		}
		while (j < n && a[j + 1] == '1') {
			++j;
		}
		c[++m1] = mkp(0, 0);
		for (int k = i; k <= j; ++k) {
			c[m1].fst += (s[k] == '0');
			c[m1].scd += (s[k] == '1');
			f[k] = m1;
		}
	}
	for (int i = 1, j = 1; i <= n; i = (++j)) {
		if (b[i] == '0') {
			continue;
		}
		while (j < n && b[j + 1] == '1') {
			++j;
		}
		d[++m2] = mkp(0, 0);
		for (int k = i; k <= j; ++k) {
			d[m2].fst += (t[k] == '0');
			d[m2].scd += (t[k] == '1');
			g[k] = m2;
		}
	}
	int ans = 0;
	for (int i = 1; i <= n; ++i) {
		if (a[i] == '0' && b[i] == '0') {
			ans += (s[i] == t[i]);
		} else if (a[i] == '0') {
			int j = g[i];
			if (s[i] == '0') {
				if (d[j].fst) {
					--d[j].fst;
					++ans;
				} else {
					assert(d[j].scd > 0);
					--d[j].scd;
				}
			} else {
				if (d[j].scd) {
					--d[j].scd;
					++ans;
				} else {
					assert(d[j].fst > 0);
					--d[j].fst;
				}
			}
		} else if (b[i] == '0') {
			int j = f[i];
			if (t[i] == '0') {
				if (c[j].fst) {
					--c[j].fst;
					++ans;
				} else {
					assert(c[j].scd > 0);
					--c[j].scd;
				}
			} else {
				if (c[j].scd) {
					--c[j].scd;
					++ans;
				} else {
					assert(c[j].fst > 0);
					--c[j].fst;
				}
			}
		}
	}
	for (int i = 1; i <= n; ++i) {
		if (a[i] == '1' && b[i] == '1') {
			int j = f[i], k = g[i];
			if (c[j].fst && d[k].fst) {
				--c[j].fst;
				--d[k].fst;
				++ans;
			} else if (c[j].scd && d[k].scd) {
				--c[j].scd;
				--d[k].scd;
				++ans;
			} else if (c[j].fst && d[k].scd) {
				--c[j].fst;
				--d[k].scd;
			} else {
				assert(c[j].scd && d[k].fst);
				--c[j].scd;
				--d[k].fst;
			}
		}
	}
	printf("%d\n", ans);
}

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