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

#define ofor(i, a, b) for (int i = a; i < b; i++)
#define cfor(i, a, b) for (int i = a; i <= b; i++)
#define bfor(i, a, b) for (int i = a; i >= b; i--)
#define mset(a, x) memset(a, x, sizeof(a))
const int X = 1e5 + 5;

int T, n, ans;
string s1, s2, t1, t2;

void INIT() {
	ans = 0;
	return;
}

bool checkA() {
	ofor (i, 0, n-1)
		if (s1[i] != s1[i+1])
			return false;
	return true;
}

bool checkB() {
	return t1 == t2;
}

bool checkC() {
	int cnt1 = 0, cnt2 = 0;
	ofor (i, 0, n) {
		if (s1[i] == '0') cnt1++;
		if (s2[i] == '0') cnt2++;
	}
	return cnt1 == 1 and cnt2 == 1;
}

void A() {
	ofor (i, 0, n)
		if (s1[i] == s2[i])	ans++;
	return;
}

void B() {
	int one1 = 0, zero1 = 0, one2 = 0, zero2 = 0;
	ofor (i, 0, n) {
		if (t1[i] == '0') {
			ans += min(one1, one2) + min(zero1, zero2);
			if (s1[i] == s2[i]) ans++;
			one1 = zero1 = one2 = zero2 = 0;
		}
		else {
			if (s1[i] == '1') one1++;
			else zero1++;
			if (s2[i] == '1') one2++;
			else zero2++;
		}
	}
	ans += min(one1, one2) + min(zero1, zero2);
	return;
}

void C() {
	return;
}

int main() {
	freopen("edit.in", "r", stdin);
	freopen("edit.out", "w", stdout);
	ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
	cin >> T;
	while (T--) {
		INIT();
		cin >> n;
		cin >> s1 >> s2 >> t1 >> t2;
		if (checkA()) A();
		else if (checkB()) B();
		else if (checkC()) C();
		cout << ans << endl;
	}
	return 0;
}
