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

const int maxn = 1e5 + 10;

int s1[maxn], s2[maxn], t1[maxn], t2[maxn];
int f1[maxn], f2[maxn];
int seg1[maxn], seg2[maxn];
int se1[maxn], se2[maxn];
int T, n;

void input() {
	cin >> n;
	for (int i = 1;i <= n;++i) {
		char c;
		cin >> c;
		s1[i] = c - '0';
	}
	for (int i = 1;i <= n;++i) {
		char c;
		cin >> c;
		s2[i] = c - '0';
	}
	for (int i = 1;i <= n;++i) {
		char c;
		cin >> c;
		t1[i] = c - '0';
	}
	for (int i = 1;i <= n;++i) {
		char c;
		cin >> c;
		t2[i] = c - '0';
	}
}

void pre() {
	for (int i = n;i >= 1;--i) {
		if (t1[i] == 0) {
			f1[i] = -1;
		} else {
			f1[i] = (f1[i+1] == -1) ? i : f1[i+1];
		}
		if (t2[i] == 0) {
			f2[i] = -1;
		} else {
			f2[i] = (f2[i+1] == -1) ? i : f2[i+1];
		}
	}
	for (int i = 1;i <= n;++i) {
		if (f1[i] != -1) seg1[f1[i]]+=s1[i], se1[f1[i]] += (s1[i] == 0);
		if (f2[i] != -1) seg2[f2[i]]+=s2[i], se2[f2[i]] += (s2[i] == 0);
	}
}

void cleanup() {
	memset(s1, 0, sizeof s1);
	memset(s2, 0, sizeof s2);
	memset(t1, 0, sizeof t1);
	memset(t2, 0, sizeof t2);
	memset(f1, 0, sizeof f1);
	memset(f2, 0, sizeof f2);
	memset(seg1, 0, sizeof seg1);
	memset(seg2, 0, sizeof seg2);
	memset(se1, 0, sizeof se1);
	memset(se2, 0, sizeof se2);
}

int main() {
	freopen("edit.in", "r", stdin);
	freopen("edit.out", "w", stdout);
	cin >> T;
	while (T--) {
		cleanup();
		input();
		pre();
		int ans = 0;
		for (int i = 1, j = 1;i <= n && j <= n;++i, ++j) {
			int r1 = f1[i], r2 = f2[j];
			if (r1 == -1) {
				if (r2 == -1) {
					ans += (s1[i] == s2[j]);
					// cout << "A" << ans << endl;
				} else {
					if (s1[i] == 1) {
						if (seg2[r2] >= 1) {
							ans++;
							seg2[r2]--;
						}
					} else {
						if (se2[r2] >= 1) {
							ans++;
							se2[r2]--;
						}
					}
					// cout << "B" << ans << endl;
				}
			} else {
				if (r2 == -1) {
					if (s2[j] == 1) {
						if (seg1[r1] >= 1) {
							ans++;
							seg1[r1]--;
						}
					} else {
						if (se1[r1] >= 1) {
							ans++;
							se1[r1]--;
						}
					}
					// cout << "C" << ans << endl;
				} else {
					if (seg1[r1] >= 1 && seg2[r2] >= 1) {
						seg1[r1]--;
						seg2[r2]--;
						ans++;
					} else if (se1[r1] >= 1 && se2[r2] >= 1) {
						se1[r1]--;
						se2[r2]--;
						ans++;
					}
					// cout << "D" << ans << endl;
				}
			}
		}
		cout << ans << endl;
	}
	fclose(stdin);
	fclose(stdout);
	return 0;
}