#include <bits/stdc++.h>
#define fi first
#define se second
#define MP make_pair
using namespace std;

const int N = 1e5 + 7;

int n;
string s, t, u, v;
pair<int, int> S[N], T[N];

void solve() {
	cin >> n >> s >> t >> u >> v;
	int cs = 0, ct = 0, cnt[2][2] = {{0}};
	for (int i = 0; i < n; i ++) {
		if (u[i] == '0') {
			S[++ cs] = MP(cnt[0][0], cnt[0][1]);
			S[++ cs] = MP((s[i] == '0'), (s[i] == '1'));
			cnt[0][0] = cnt[0][1] = 0;
		} else cnt[0][s[i] - '0'] ++;
		if (v[i] == '0') {
			T[++ ct] = MP(cnt[1][0], cnt[1][1]);
			T[++ ct] = MP((t[i] == '0'), (t[i] == '1'));
			cnt[1][0] = cnt[1][1] = 0;
		} else cnt[1][t[i] - '0'] ++;
	}
	S[++ cs] = MP(cnt[0][0], cnt[0][1]);
	T[++ ct] = MP(cnt[1][0], cnt[1][1]);
	int shx = 1, yzx = 1, ans = 0;
	while (shx <= cs && yzx <= ct) {
		int lzy = min(S[shx].fi, T[yzx].fi);
		S[shx].fi -= lzy, T[yzx].fi -= lzy, ans += lzy;
		lzy = min(S[shx].se, T[yzx].se);
		S[shx].se -= lzy, T[yzx].se -= lzy, ans += lzy;
		if (S[shx].fi + S[shx].se < T[yzx].fi + T[yzx].se) {
			T[yzx].fi -= S[shx].se;
			T[yzx].se -= S[shx].fi, shx ++;
		} else {
			S[shx].fi -= T[yzx].se;
			S[shx].se -= T[yzx].fi, yzx ++;
		}
	}
	cout << ans << '\n';
}

int main() {
	freopen("edit.in", "r", stdin);
	freopen("edit.out", "w", stdout);
	ios::sync_with_stdio(0);
	int tt; cin >> tt;
	while (tt --) solve();
	return 0;
}
 
