#include <bits/stdc++.h>
#define ll int
#define pir pair <ll, ll>
#define fi first
#define se second
#define pb emplace_back
using namespace std;

void rd(ll &x) {
	char ch; bool f = 0;
	while(!isdigit(ch = getchar()))
		if(ch == '-') f = 1;
	x = ch - '0';
	while(isdigit(ch = getchar()))
		x = (x << 1) + (x << 3) + ch - '0';
	if(f) x = -x;
}

const ll maxn = 1e5 + 10;
ll t, n, cnta[maxn][2], cntb[maxn][2], lsta[maxn], lstb[maxn];
char a[maxn], b[maxn], p[maxn], q[maxn];
void solve() {
	rd(n), scanf("%s%s%s%s", a + 1, b + 1, p + 1, q + 1);
	memset(cnta, 0, sizeof cnta);
	memset(cntb, 0, sizeof cntb);
	for(ll i = 1; i <= n; i++) {
		lsta[i] = i, ++cnta[i][a[i] - '0'];
		if(p[i] == '1') {
			ll j = i;
			while(p[j + 1] == '1')
				lsta[++j] = i, ++cnta[i][a[j] - '0'];
			i = j;
		}
	}
	for(ll i = 1; i <= n; i++) {
		lstb[i] = i, ++cntb[i][b[i] - '0'];
		if(q[i] == '1') {
			ll j = i;
			while(q[j + 1] == '1')
				lstb[++j] = i, ++cntb[i][b[j] - '0'];
			i = j;
		}
	} ll ans = 0;
	for(ll i = 1; i <= n; i++) {
		ll x = lsta[i], y = lstb[i];
		if(cnta[x][0] && cntb[y][0])
			--cnta[x][0], --cntb[y][0], ++ans;
		else if(cnta[x][1] && cntb[y][1])
			--cnta[x][1], --cntb[y][1], ++ans;
	} printf("%d\n", ans);
}
int main() {
	freopen("edit.in", "r", stdin);
	freopen("edit.out", "w", stdout);
	rd(t); while(t--) solve();
	return 0;
}
