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

typedef long long ll;

ll getInt() {
	ll s = 0, f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar())
		if (c == '-') f = -1;
	for (; isdigit(c); c = getchar())
		s = s * 10 + c - '0';
	return s * f;
}

char getChar() {
	char c = getchar();
	while (isspace(c)) c = getchar();
	return c;
}

const int N = 1e5 + 10;

ll s1[N], s2[N], t1[N], t2[N];

ll ans;

struct Range {
	ll l, r, sum0, sum1;
};

vector<Range> rg1, rg2;

void make_range(ll n) {
	ll sum0 = 0, sum1 = 0, l = 1, r = 0;
	for (int i = 1; i <= n; ++i) {
		if (t1[i] == 1) {
			sum0 += (s1[i] == 0);
			sum1 += (s1[i] == 1);
			++r;
			if (t1[i + 1] == 0) {
				rg1.push_back({l, r, sum0, sum1});
				l = r + 1;
				sum0 = sum1 = 0; 
			}
		} else {
			sum0 += (s1[i] == 0);
			sum1 += (s1[i] == 1);
			++r;
			rg1.push_back({l, r, sum0, sum1});
			l = r + 1;
			sum0 = sum1 = 0; 
		}
	}
	sum0 = sum1 = 0;
	l = 1, r = 0;
	for (int i = 1; i <= n; ++i) {
		if (t2[i] == 1) {
			sum0 += (s2[i] == 0);
			sum1 += (s2[i] == 1);
			++r;
			if (t2[i + 1] == 0) {
				rg2.push_back({l, r, sum0, sum1});
				l = r + 1;
				sum0 = sum1 = 0; 
			}
		} else {
			sum0 += (s2[i] == 0);
			sum1 += (s2[i] == 1);
			++r;
			rg2.push_back({l, r, sum0, sum1});
			l = r + 1;
			sum0 = sum1 = 0; 
		}
	}
}

ll getAns(Range x, Range y) {
	ll t = min(x.sum0, y.sum0), tt = min(x.sum1, y.sum1);
	x.sum0 -= t, y.sum0 -= t;
	x.sum1 -= tt, y.sum1 -= tt;
	return t + tt;
}

void work() {

	ll n = getInt();
	bool flag1 = 1;
	bool flag2 = 1;
	for (int i = 1; i <= n; ++i) {
		s1[i] = getChar() == '1';
		if (i >= 2 && s1[i] != s1[i - 1]) {
			flag1 = 0;
		}
	}

	for (int i = 1; i <= n; ++i) {
		s2[i] = getChar() == '1';
	}

	for (int i = 1; i <= n; ++i) {
		t1[i] = getChar() == '1';

	}

	for (int i = 1; i <= n; ++i) {
		t2[i] = getChar() == '1';
		if (t1[i] != t2[i]) {
			flag2 = 0;
		}
	}

	ans = 0;
	s1[n + 1] = 1;
	s2[n + 1] = 0;
	t1[n + 1] = t2[n + 1] = 0;

	if (flag1) {
		for (int i = 1; i <= n; ++i) {
			if (s1[i] == s2[i]) {
				++ans;
			}
		}
	} else if (flag2) {
		ll sum1[2] = {0, 0}, sum2[2] = {0, 0};
		for (int i = 1; i <= n + 1; ++i) {
			if (t1[i] == 1) {
				++sum1[s1[i]];
				++sum2[s2[i]];
			} else {
				ans += (s1[i] == s2[i]);
				ans += min(sum1[0], sum2[0]);
				ans += min(sum1[1], sum2[1]);
				sum1[0] = sum2[0] = sum1[1] = sum2[1] = 0;
			}
		}
	} else {
		make_range(n);
		ll x = 1, y = 1;
		while (1) {
			ans += getAns(rg1[x], rg2[y]); 
			if (rg1[x].r < rg2[y].r) {
				++x;
			} else {
				++y;
			}
			if (x == rg1.size() || y == rg2.size()) break;
		}
	}

	printf("%lld\n", ans);
}

int main() {
	freopen("edit.in", "r", stdin);
	freopen("edit.out", "w", stdout);
	ll t = getInt();
	while (t--) {
		work();
	}

	fclose(stdin);
	fclose(stdout);
	return 0;
}
