#include <iostream>
#include <algorithm>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
const int MAX_N = 1e5 + 5;

int t, n, ans;
char s1[MAX_N], s2[MAX_N];
char t1[MAX_N], t2[MAX_N];

int sz1, sz2;
struct Range {
	int l, r, cnt0, cnt1;
} r1[MAX_N], r2[MAX_N];

int main() {
	freopen("edit.in", "r", stdin);
	freopen("edit.out", "w", stdout);
	ios::sync_with_stdio(false); cin.tie(nullptr);
	cin >> t;
	while (t--) {
		cin >> n;
		cin >> (s1 + 1) >> (s2 + 1);
		cin >> (t1 + 1) >> (t2 + 1);
		sz1 = sz2 = ans = 0;
		Range cur = { 1, 1, s1[1] == '0', s1[1] == '1' };
		for (int i = 2; i <= n; ++i) {
			if (t1[i] == '1' && t1[i - 1] == '1') ++cur.r;
			else {
				r1[++sz1] = cur;
				cur.l = cur.r = i;
				cur.cnt0 = cur.cnt1 = 0;
			}
			if (s1[i] == '1') ++cur.cnt1;
			else ++cur.cnt0;
		}
		r1[++sz1] = cur;
		cur = { 1, 1, s2[1] == '0', s2[1] == '1' };
		for (int i = 2; i <= n; ++i) {
			if (t2[i] == '1' && t2[i - 1] == '1') ++cur.r;
			else {
				r2[++sz2] = cur;
				cur.l = cur.r = i;
				cur.cnt0 = cur.cnt1 = 0;
			}
			if (s2[i] == '1') ++cur.cnt1;
			else ++cur.cnt0;
		}
		r2[++sz2] = cur;
		int i = 1, j = 1;
		while (i <= sz1 && j <= sz2) {
			if (r1[i].r >= r2[j].r) {
				while (j <= sz2 && r1[i].r >= r2[j].r) {
					if (r1[i].cnt0 >= r2[j].cnt0) {
						ans += r2[j].cnt0;
						r1[i].cnt0 -= r2[j].cnt0;
					} else {
						ans += r1[i].cnt0;
						r2[j].cnt0 -= r1[i].cnt0;
						r1[i].cnt0 = 0;
						r1[i].cnt1 -= r2[j].cnt0;
					}
					if (r1[i].cnt1 >= r2[j].cnt1) {
						ans += r2[j].cnt1;
						r1[i].cnt1 -= r2[j].cnt1;
					} else {
						ans += r1[i].cnt1;
						r2[j].cnt1 -= r1[i].cnt1;
						r1[i].cnt1 = 0;
						r1[i].cnt0 -= r2[j].cnt1;
					}
					++j;
				}
				r1[i].l = r2[j].l;
				if (r1[i].l > r1[i].r) ++i;
			} else {
				while (i <= sz1 && r1[i].r < r2[j].r) {
					if (r1[i].cnt0 <= r2[j].cnt0) {
						ans += r1[i].cnt0;
						r2[j].cnt0 -= r1[i].cnt0;
					} else {
						ans += r2[j].cnt0;
						r1[i].cnt0 -= r2[j].cnt0;
						r2[j].cnt0 = 0;
						r2[j].cnt1 -= r1[i].cnt0;
					}
					if (r1[i].cnt1 <= r2[j].cnt1) {
						ans += r1[i].cnt1;
						r2[j].cnt1 -= r1[i].cnt1;
					} else {
						ans += r2[j].cnt1;
						r1[i].cnt1 -= r2[j].cnt1;
						r2[j].cnt1 = 0;
						r2[j].cnt0 -= r1[i].cnt1;
					}
					++i;
				}
				r2[j].l = r1[i].l;
				if (r2[j].l > r2[j].r) ++j;
			}
		}
		cout << ans << '\n';
	}
	cout.flush();
	fclose(stdin);
	fclose(stdout);
	return 0;
}
