#include <bits/stdc++.h>
#define fst first
#define snd second
using namespace std;
using ll = long long;
using ld = long double;

const long long IMX = 1ll << 30;
const long long LMX = 1ll << 60;
const int N = 100005;
int T, n, ans;
int s1[N], s2[N];
void work1(int l, int r) {
	if (l > r) return ;
	int c1 = 0, c0 = 0;
	for (int i = l; i <= r; i++) c1 += (s1[i] == 1), c0 += (s1[i] == 0);
	for (int i = l; i <= r; i++) {
		if (s2[i] == 0) {
			if (c0) c0--, s1[i] = 0;
			else s1[i] = 1;
		}
		else {
			if (c1) c1--, s1[i] = 1;
			else s1[i] = 0;
		}
	}
}
void work2(int l, int r) {
	if (l > r) return ;
	int c1 = 0, c0 = 0;
	for (int i = l; i <= r; i++) c1 += (s2[i] == 1), c0 += (s2[i] == 0);
	for (int i = l; i <= r; i++) {
		if (s1[i] == 0) {
			if (c0) c0--, s2[i] = 0;
			else s2[i] = 1;
		}
		else {
			if (c1) c1--, s2[i] = 1;
			else s2[i] = 0;
		}
	}
}
void work3(int l, int r) {
	if (l > r) return ;
	int c1 = 0, c2 = 0;
	for (int i = l; i <= r; i++) c1 += (s1[i] == 0), c2 += (s2[i] == 0);
	for (int i = l; i <= r; i++) {
		if (c1) c1--, s1[i] = 0;
		else s1[i] = 1;
		if (c2) c2--, s2[i] = 0;
		else s2[i] = 1;
	}
}
int main() {
	ios :: sync_with_stdio(0);
	cin.tie(nullptr);
	freopen("edit.in", "r", stdin);
	freopen("edit.out", "w", stdout);
	cin >> T;
	while (T--) {
		ans = 0;
		int len1 = 0, len2 = 0, len3 = 0;
		string tmp1, tmp2, t1, t2;
		cin >> n >> tmp1 >> tmp2 >> t1 >> t2;
		for (int i = 0; i < n; i++) s1[i + 1] = tmp1[i] - '0', s2[i + 1] = tmp2[i] - '0';
		t1 = ' ' + t1;
		t2 = ' ' + t2;
		for (int i = 1; i <= n; i++) {
			if (t1[i] == '1' and t2[i] == '1') len3++;
			else {
				if (len3) {
					work3(i - len3, i - 1);
					len3 = 0;
				}
			}
		}
		if (len3) work3(n - len3 + 1, n);
		for (int i = 1; i <= n; i++) {
			if (t1[i] == '1') len1++;
			else {
				if (len1) {
					work1(i - len1, i - 1);   
					len1 = 0;
				}
			}
		}
		if (len1) work1(n - len1 + 1, n);
		for (int i = 1; i <= n; i++) {
			if (t2[i] == '1') len2++;
			else {
				if (len2) {
					work2(i - len2, i - 1);   
					len2 = 0;
				}
			}
		}
		if (len2) work2(n - len2 + 1, n);
		len1 = len2 = len3 = 0;
		for (int i = 1; i <= n; i++) {
			if (t1[i] == '1' and t2[i] == '1') len3++;
			else {
				if (len3) {
					work3(i - len3, i - 1);
					len3 = 0;
				}
			}
		}
		if (len3) work3(n - len3 + 1, n);
		for (int i = 1; i <= n; i++) {
			if (t1[i] == '1') len1++;
			else {
				if (len1) {
					work1(i - len1, i - 1);   
					len1 = 0;
				}
			}
		}
		if (len1) work1(n - len1 + 1, n);
		for (int i = 1; i <= n; i++) {
			if (t2[i] == '1') len2++;
			else {
				if (len2) {
					work2(i - len2, i - 1);   
					len2 = 0;
				}
			}
		}
		if (len2) work2(n - len2 + 1, n);
		for (int i = 1; i <= n; i++) ans += (s1[i] == s2[i]);
		cout << ans << '\n';
	}
	return 0;
}
