#include <bits/stdc++.h>
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define F(i, x, y) for (int i = (x); i <= (y); i++)
#define R(i, x, y) for (int i = (x); i >= (y); i--)
#define FIO(FILE) freopen(FILE".in", "r", stdin), freopen(FILE".out", "w", stdout);

using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
bool Mbe;

const int N = 1e5 + 5;

int n, l, r, k, res;
char s[N], t[N], v1[N], v2[N];

pi G[N], H[N];

void merge(int L, int R, int K) {
	if (l == -1) {
		l = L, r = R, k = K;
		return;
	}
	if (r == R) {
		res += abs(k - K);
		l = r = -1, k = 0;
		return;
	}
	if (R < r) {
		swap(l, L);
		swap(r, R);
		swap(k, K);
	}
	if (k <= K) {
		if (K - k > R - r) {
			res += (K - k) - (R - r);
			k = R - r;
			l = r + 1, r = R;
		} else {
			l = r + 1, r = R, k = K - k;
		}
	} else {
		res += k - K;
		l = r + 1, r = R, k = 0;
	} 
}

void solve() {
	cin >> n >> (s + 1) >> (t + 1) >> (v1 + 1) >> (v2 + 1);
	F (i, 1, n) {
		G[i] = H[i] = mp(0, 0);
	}
	F (i, 1, n) {
		if (v1[i] == '1') {
			int j = i, ct = (s[i] == '1');
			while (j < n && (v1[j + 1] == '1')) {
				j++, ct += (s[j] == '1');
			}
			G[i] = mp(j, ct);
			i = j;
		} else {
			G[i] = mp(i, s[i] - '0');
		}
	}
	F (i, 1, n) {
		if (v2[i] == '1') {
			int j = i, ct = (t[i] == '1');
			while (j < n && (v2[j + 1] == '1')) {
				j++, ct += (t[j] == '1');
			}
			H[i] = mp(j, ct);
			i = j;
		} else {
			H[i] = mp(i, t[i] - '0');
		}
	}
	l = r = -1, k = res = 0;
	F (i, 1, n) {
		if (G[i].fi) {
			merge(i, G[i].fi, G[i].se);
		}
		if (H[i].fi) {
			merge(i, H[i].fi, H[i].se);
		}
	}
	cout << n - res << '\n';
}

bool Med;
int main() {
	FIO("edit");
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cerr << (&Mbe - &Med) / 1048576. << " MB\n";
	int T = 1;
	cin >> T;
	while (T--) solve();
	cerr << 1. * clock() / CLOCKS_PER_SEC << " ms\n";
	return 0;
}
