#include <bits/stdc++.h>
#define LL long long
#define ULL unsigned long long
#define LLL __int128
#define pii pair<int, int>
#define fi first
#define se second
#define mkp make_pair
using namespace std;

int read() {
	int s = 0, f = 1;
	char ch = getchar();
	while (ch < '0' || ch > '9') f = (ch == '-' ? -1 : 1), ch = getchar();
	while (ch >= '0' && ch <= '9') s = (s << 1) + (s << 3) + (ch ^ 48), ch = getchar();
	return s * f;
}

int read01() {
	char ch = getchar();
	while (ch != '0' && ch != '1') ch = getchar();
	return ch - '0';
}

template <typename T>
void chkmn(T &x, T y) { x = x < y ? x : y;}
template <typename T>
void chkmx(T &x, T y) { x = y < x ? x : y;}

const int MAXN = 100005;

int n;
int s[2][MAXN], t[2][MAXN];
int cnt[2][MAXN][2], num[2], sum[2][2];

void work() {
	n = read();
	for (int o = 0; o < 2; o++)
		for (int i = 1; i <= n; i++) s[o][i] = read01();
	for (int o = 0; o < 2; o++)
		for (int i = 1; i <= n; i++) t[o][i] = read01();
	for (int o = 0; o < 2; o++) {
		for (int i = 1; i <= n; i++)
			for (int j = 0; j < 2; j++) cnt[o][i][j] = 0;
		num[0] = num[1] = 0;
		for (int i = n; i; i--) {
			num[s[o][i]]++;
			if (i == 1 || !t[o][i - 1] || !t[o][i]) cnt[o][i][0] = num[0], cnt[o][i][1] = num[1], num[0] = num[1] = 0;
		}
	}
	memset(sum, 0, sizeof sum);
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		for (int o = 0; o < 2; o++)
			for (int j = 0; j < 2; j++)
				sum[o][j] += cnt[o][i][j];
		if (sum[0][0] && sum[1][0]) ans++, sum[0][0]--, sum[1][0]--;
		else if (sum[0][1] && sum[1][1]) ans++, sum[0][1]--, sum[1][1]--;
		else if (sum[0][0]) sum[0][0]--, sum[1][1]--;
		else sum[0][1]--, sum[1][0]--;
	}
	printf("%d\n", ans);
}

int main() {
	freopen("edit.in", "r", stdin);
	freopen("edit.out", "w", stdout);
	int T = read();
	while (T--) work(); 
	return 0;
}
