#include <bits/stdc++.h>

#ifdef XSLOCAL
//#define XS_DEBUG_MODE
#endif

#ifndef XS_DEBUG_MODE
#define dblog(str, args...)
#else
#define dblog(str, args...) (fprintf(stderr, str, ##args))
#endif

namespace xiaosuan {

using std::min;
using std::max;
using std::bitset;

const int MAX_N = int(1e5);

int n;
bitset <MAX_N + 10> A[2];
bitset <MAX_N + 10> B[2];

int S[2][2][2];

template <typename T>
void bstrrd(T &bstr) {
	bstr[0] = 0;
	for (int i = 1; i <= n; ++i) {
		int a;
		scanf("%1d", &a);
		bstr[i] = a;
	}
}

int main() {
	freopen("edit.in", "r", stdin);
	freopen("edit.out", "w", stdout);
	int T;
	scanf("%d", &T);
	while (T--) {
		scanf("%d", &n);
		bstrrd(A[0]);
		bstrrd(A[1]);
		bstrrd(B[0]);
		bstrrd(B[1]);
		memset(S, 0, sizeof(S));
		int ans = 0;
		for (int i = 1; i <= n; ++i) {
			for (int j = 0; j != 2; ++j) {
				if (!B[j][i] || !B[j][i - 1]) {
					S[j][0][1] += S[j][0][0];
					S[j][1][1] += S[j][1][0];
					S[j][0][0] = S[j][1][0] = 0;
				}
				++S[j][A[j][i]][0];
			}
			int sz = S[0][0][0] + S[0][1][0] - S[1][0][0] - S[1][1][0];
			for (int j = 0; j != 2; ++j) {
				S[0][j][1] = min(S[0][j][1], max(-sz, 0));
				S[1][j][1] = min(S[1][j][1], max(sz, 0));
			}
			for (int j =0; j != 2; ++j) {
				int mn = min(S[0][j][0] + S[0][j][1], S[1][j][0] + S[1][j][1]);
				for (int k = 0; k != 2; ++k) {
					int decf = min(mn, S[k][j][1]);
					S[k][j][0] -= mn - decf;
					S[k][j][1] -= decf;
				}
				ans += mn;
			}
		}
		printf("%d\n", ans);
	}
	return 0;
}

}

int main() {
	return xiaosuan::main();
}
