#include <bits/stdc++.h>
#define USE_FREOPEN
#define MUL_TEST
#define FILENAME "edit"

const int N = 1e5 + 5;
int n, res, cnter[2][2][N];
int tot[2][2][2];
std::string s1, s2, t1, t2;
std::vector<int> vec1, vec2;
int zss[2], oss[2];

void solve() {
	res = 0;
	scanf("%d", &n);
	std::cin >> s1 >> s2 >> t1 >> t2;
	bool flag_a = 1, flag_b = 0, flag_c = 1;
	int cnt = 0;
	flag_b = t1 == t2;
	for (int i = 1; i < n; ++i) if (s1[i] != s1[i - 1]) flag_a = 0;
	for (int i = 0; i < n; ++i) cnt += t1[i] == '0';
	if (cnt != 1) flag_c = 0;
	cnt = 0;
	for (int i = 0; i < n; ++i) cnt += t2[i] == '0';
	if (cnt != 1) flag_c = 0;
	int ans = 0;
	if (flag_a) {
		for (int i = 0; i < n; ++i) if (s2[i] == s1[i]) ++ans;
		printf("%d\n", ans);
	}
	else if (flag_b) {
		vec1.clear(); vec2.clear();
		for (auto c : s1) vec1.push_back(c - '0');
		for (auto c : s2) vec2.push_back(c - '0');
		int beg = -1, end;
		for (int i = 0; i <= n; ++i) {
			if (i == n || t1[i] == '0') {
				if (!~beg) continue;
				end = i;
				std::sort(vec1.begin() + beg, vec1.begin() + end);
				std::sort(vec2.begin() + beg, vec2.begin() + end);
				beg = -1;
			}
			if (t1[i] == '1') {
				if (!~beg) beg = i;
			}
		}
		for (int i = 0; i < n; ++i) if (vec1[i] == vec2[i]) ++ans;
		printf("%d\n", ans);
	}
	else {
		memset(tot, 0, sizeof tot);
		int p1 = t1.find('0');
		int p2 = t2.find('0');
		if (p1 > p2) std::swap(p1, p2), std::swap(s1, s2);
		
		for (int i = 0; i < p1; ++i) ++tot[0][s1[i] - '0'][0];
		for (int i = p1 + 1; i < n; ++i) ++tot[0][s1[i] - '0'][1];
		for (int i = 0; i < p2; ++i) ++tot[1][s2[i] - '0'][0];
		for (int i = p2 + 1; i < n; ++i) ++tot[1][s2[i] - '0'][1];
		
		int zero, one;
		// 1. p1 left with p2 left
		if (tot[1][s1[p1] - '0'][0])
			--tot[1][s1[p1] - '0'][0], ++ans;
		zero = std::min(tot[0][0][0], tot[1][0][0]);
		one = std::min(tot[0][1][0], tot[1][1][0]);
		tot[0][0][0] = tot[0][1][0] = 0;
		tot[1][1][0] -= one, tot[1][0][0] -= zero;
		ans += one + zero;
		
		// 2. p1 right with p2 left(left)
		if (tot[0][s2[p2] - '0'][0])
			--tot[0][s2[p2] - '0'][0], ++ans;
		zero = std::min(tot[0][0][1], tot[1][0][0]);
		one = std::min(tot[0][1][1], tot[1][1][0]);
		tot[1][0][0] = tot[1][1][0] = 0;
		tot[0][0][1] -= zero, tot[0][1][1] -= one;
		ans += one + zero;
		
		// 3. p1 right(left) with p2 right
		zero = std::min(tot[0][0][1], tot[1][0][1]);
		one = std::min(tot[0][1][1], tot[1][1][1]);
		ans += one + zero;
		printf("%d", ans);
	}
	
}

signed main() {
#ifdef USE_FREOPEN
	freopen(FILENAME ".in", "r", stdin);
//	freopen(FILENAME ".out", "w", stdout);
#endif

	int _ = 1;
#ifdef MUL_TEST
	scanf("%d", &_);
#endif
	while (_--) solve();
	_ ^= _;
	return (0^_^0);
}


