#include <bits/stdc++.h>
using namespace std;

long long read() {
	long long x = 0, k = 1;
	char c = getchar();
	while (c != '-' && (c < '0' || c > '9')) c = getchar();
	if (c == '-') k = -1, c = getchar();
	while (c >= '0' && c <= '9') x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
	return x * k;
}

const int N = 1e5 + 7;

struct LZY {
	int l, r;
};

int n;
string s1, s2, t1, t2;
LZY p1[N], p2[N];

void init() {
	
}

void solve() {
	n = read();
//	init();
	cin >> s1; s1 = " " + s1;
	cin >> s2; s2 = " " + s2;
	cin >> t1; t1 = " " + t1;
	cin >> t2; t2 = " " + t2;
	int cnt1 = 0, l = 1, cnt2;
	for (int i = 2; i <= n + 1; i ++) {
		if (t1[i - 1] == '0') {
			p1[++ cnt1] = {l, l};
			l = i;
		} else if (i > n || t1[i] == '0') {
			p1[++ cnt1] = {l, i - 1};
			l = i;
		}
	}
//	cout << "p1 : ";
//	for (int i = 1; i <= cnt1; i ++)
//		printf("(%d, %d)", p1[i].l, p1[i].r);
//	cout << '\n'; 
	cnt2 = 0, l = 1;
	for (int i = 2; i <= n + 1; i ++) {
		if (t2[i - 1] == '0') {
			p2[++ cnt2] = {l, l};
			l = i;
		} else if (i > n || t2[i] == '0') {
			p2[++ cnt2] = {l, i - 1};
			l = i;
		}
	}
//	cout << "p2 : ";
//	for (int i = 1; i <= cnt2; i ++)
//		printf("(%d, %d)", p2[i].l, p2[i].r);
//	cout << '\n'; 
	int i = 1, j = 1, li = 1, lj = 1;
	int wjc0 = 0, wjc1 = 0, lzy0 = 0, lzy1 = 0;
	int ans = 0;
	while (i <= cnt1 && j <= cnt2) {
//		printf("(i, j) = (%d, %d)\n", i, j);
		while (li <= p1[i].r) {
			wjc0 += (s1[li] == '0');
			wjc1 += (s1[li] == '1');
			li ++;
		}
//		printf("p1 : (%d, %d), now = (%d, %d)\n", p1[i].l, p1[i].r, wjc0, wjc1);
		while (lj <= p2[j].r) {
			lzy0 += (s2[lj] == '0');
			lzy1 += (s2[lj] == '1');
			lj ++;
		}
//		printf("p2 : (%d, %d), now = (%d, %d)\n", p2[j].l, p2[j].r, lzy0, lzy1);
		int mn0 = min(wjc0, lzy0);
		int mn1 = min(wjc1, lzy1);
		int len = min(p1[i].r, p2[j].r) - max(p1[i].l, p2[j].l) + 1;
		ans += mn0 + mn1;
		wjc0 -= mn0, lzy0 -= mn0;
		wjc1 -= mn1, lzy1 -= mn1;
		if (len > mn0 + mn1) {
			len -= mn0 + mn1;
			if (wjc0) wjc0 -= len;
			if (wjc1) wjc1 -= len;
			if (lzy0) lzy0 -= len;
			if (lzy1) lzy1 -= len;
		}
		if (li <= lj) i ++, wjc0 = wjc1 = 0;
		if (lj <= li) j ++, lzy0 = lzy1 = 0;
	}
	cout << ans << '\n';
}

signed main() {
	freopen("edit.in", "r", stdin);
	freopen("edit.out", "w", stdout);
	int t = 1;
	t = read();
	while (t --)
		solve();
	return 0;
}
/*
//freopen("edit.in", "r", stdin);
//freopen("edit.out", "w", stdout);
//freopen("edit.in", "r", stdin);
//freopen("edit.out", "w", stdout);
//freopen("edit.in", "r", stdin);
//freopen("edit.out", "w", stdout);
//freopen("edit.in", "r", stdin);
//freopen("edit.out", "w", stdout);
//freopen("edit.in", "r", stdin);
//freopen("edit.out", "w", stdout);
//freopen("edit.in", "r", stdin);
//freopen("edit.out", "w", stdout);
*/ 
