#include <algorithm>
#include <iostream>
#include <cstring>
#include <cctype>
#include <cstdio>
using namespace std;
namespace IO {
	inline int Read() {
		int x = 0, k = 0; char ch = getchar();
		while (!isdigit(ch)) k |= (ch == '-'), ch = getchar();
		while (isdigit(ch)) x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar();
		return k ? -x : x;
	}
}
const int MaxN = 1E5 + 10;
int n, T;
int a[MaxN], b[MaxN], A[MaxN], B[MaxN];
void Input() {
	n = IO::Read();
	for (register int i = 1; i <= n; i++) {
		char ch = getchar();
		while (ch != '0' && ch != '1') ch = getchar();
		a[i] = ch - '0';
	}
	for (register int i = 1; i <= n; i++) {
		char ch = getchar();
		while (ch != '0' && ch != '1') ch = getchar();
		b[i] = ch - '0';
	}
	for (register int i = 1; i <= n; i++) {
		char ch = getchar();
		while (ch != '0' && ch != '1') ch = getchar();
		A[i] = ch - '0';
	}
	for (register int i = 1; i <= n; i++) {
		char ch = getchar();
		while (ch != '0' && ch != '1') ch = getchar();
		B[i] = ch - '0';
	}
}
bool Check1() {
	for (register int i = 2; i <= n; i++) {
		if (a[i] != a[i - 1]) return false;
	}
	return true;
}
bool Check2() {
	for (register int i = 1; i <= n; i++) {
		if (A[i] != B[i]) return false;
	}
	return true;
}
bool Check3() {
	int sum = 0;
	for (register int i = 1; i <= n; i++) sum += A[i];
	if (sum != n - 1) return false;
	sum = 0;
	for (register int i = 1; i <= n; i++) sum += B[i];
	if (sum != n - 1) return false;
	return true;
}
void SPJA() {
	int ans = 0;
	for (register int i = 1; i <= n; i++) {
		if (a[i] == b[i]) ans++;
	}
	cout << ans << endl;
}
int sumA[MaxN], sumB[MaxN];
int L[MaxN], R[MaxN];
void SPJB() {
	int ans = 0, N = 0;
	for (register int i = 1; i <= n; i++) sumA[i] = sumA[i - 1] + a[i];
	for (register int i = 1; i <= n; i++) sumB[i] = sumB[i - 1] + b[i];
	for (register int i = 1; i <= n; i++) {
		if (!A[i] || !A[i - 1]) L[++N] = i;
	}
	int cnt = N;
	for (register int i = 1; i < N; i++) R[i] = L[i + 1] - 1;
	R[N] = n;
	for (register int i = 1; i <= N; i++) {
		int x = sumA[R[i]] - sumA[L[i] - 1];
		int y = sumB[R[i]] - sumB[L[i] - 1];
		ans += abs(x - y);
	}
	cout << n - ans << endl;
}
int La[MaxN], Ra[MaxN], Rb[MaxN];
bool vis[MaxN];
void Init() {
	memset(La, 0, sizeof(La));
	memset(Ra, 0, sizeof(Ra));
	memset(Rb, 0, sizeof(Rb));
	La[0] = 0, Ra[n + 1] = Rb[n + 1] = n + 1;
	for (register int i = 1; i <= n; i++) {
		if (!A[i]) La[i] = Ra[i] = i;
		if (!B[i]) Rb[i] = i;
	}
	for (register int i = 1; i <= n; i++) {
		if (!A[i]) continue;
		if (!A[i - 1]) La[i] = i;
		else La[i] = La[i - 1];
	}
	for (register int i = n; i >= 1; i--) {
		if (!A[i]) continue;
		if (!A[i + 1]) Ra[i] = i;
		else Ra[i] = Ra[i + 1];
	}
	for (register int i = n; i >= 1; i--) {
		if (!B[i]) continue;
		if (!B[i + 1]) Rb[i] = i;
		else Rb[i] = Rb[i + 1];
	}
}
void Solve() {
	Init();
	int q = 1;
	memset(vis, false, sizeof(vis));
	int ans = 0;
	while (q <= n) {
		bool flag = false;
		for (register int i = La[q]; i <= Ra[q]; i++) {
			if (!vis[i] && a[i] == b[q]) {
				vis[i] = flag = true, q++;
				break;
			}
		}
		if (flag) continue;
		for (register int i = q + 1; i <= Rb[q]; i++) {
			if (b[i] != b[q]) {
				swap(b[i], b[q]);
				break;
			}
		}
		for (register int i = La[q]; i <= Ra[q]; i++) {
			if (!vis[i] && a[i] == b[q]) {
				vis[i] = flag = true, q++;
				break;
			}
		}
		if (!flag) { ans++; q++; }
	}
	cout << n - ans << endl;
}
int main() {
	freopen("edit.in", "r", stdin);
	freopen("edit.out", "w", stdout);
	T = IO::Read();
	while (T--) {
		Input();
		if (Check1()) SPJA();
		else if (Check2()) SPJB();
		else Solve();
	}
	return 0;
} 
/*
10
1111111111
0011100101
0111111001
1101011100
*/
