// 注意到每次交换相邻两个字符且有位置不能参与交换的限制本质就是有若干个连续段可以段内重排。 
// 又因为每一对匹配仅有 1 的贡献，很容易想到如下贪心思路： 
// 枚举每个位置，并考虑这个位置所在的连续段，若有可能拉出两个元素使其产生贡献，则随便拉一组填上。 

#include <bits/stdc++.h>
#define il inline
using namespace std;
const int N = 1e5 + 3;
int n;
char s1[N], s2[N], t1[N], t2[N];
pair<int, int> ps1[N], ps2[N];
int cnt1[2][N], cnt2[2][N];
il void solve() {
	cin >> n;
	for (int i = 1; i <= n; i++) cin >> s1[i];
	for (int i = 1; i <= n; i++) cin >> s2[i];
	for (int i = 1; i <= n; i++) cin >> t1[i];
	for (int i = 1; i <= n; i++) cin >> t2[i];
	int cs1 = 0, cs2 = 0;
	ps1[++cs1] = {1, 1}, cnt1[0][cs1] = cnt1[1][cs1] = 0, cnt1[s1[1] - '0'][cs1]++;
	for (int i = 2; i <= n; i++) {
		if (t1[i] == '0' || (i >= 2 && t1[i - 1] == '0')) ps1[++cs1] = {i, i}, cnt1[0][cs1] = cnt1[1][cs1] = 0;
		else ps1[cs1].second = i;
		cnt1[s1[i] - '0'][cs1]++;
	}
	ps2[++cs2] = {1, 1}, cnt2[0][cs2] = cnt2[1][cs2] = 0, cnt2[s2[1] - '0'][cs2]++;
	for (int i = 2; i <= n; i++) {
		if (t2[i] == '0' || (i >= 2 && t2[i - 1] == '0')) ps2[++cs2] = {i, i}, cnt2[0][cs2] = cnt2[1][cs2] = 0;
		else ps2[cs2].second = i;
		cnt2[s2[i] - '0'][cs2]++;
	}
//	for (int i = 1; i <= cs1; i++) cout << ps1[i].first << ' ' << ps1[i].second << ": " << cnt1[0][i] << ' ' << cnt1[1][i] << endl;
//	cout << endl;
//	for (int i = 1; i <= cs2; i++) cout << ps2[i].first << ' ' << ps2[i].second << ": " << cnt2[0][i] << ' ' << cnt2[1][i] << endl;
//	cout << endl;
//	return;
	int ans = 0;
	int is1 = 0, is2 = 0;
	for (int i = 1, j; i <= n; i++) {
		if (i > ps1[is1].second) ++is1;
		if (i > ps2[is2].second) ++is2;
		if (cnt1[0][is1] > 0 && cnt2[0][is2] > 0) ++ans, --cnt1[0][is1], --cnt2[0][is2];
		else if (cnt1[1][is1] > 0 && cnt2[1][is2] > 0) ++ans, --cnt1[1][is1], --cnt2[1][is2];
	}
	cout << ans << '\n';
}
signed main() {
	freopen("edit.in", "r", stdin);
	freopen("edit.out", "w", stdout);
	ios::sync_with_stdio(false), cin.tie(nullptr);
	int T; cin >> T;
	while (T--) solve();
	return 0;
}
