#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <bitset>
#include <cstdlib>

using namespace std;

const int maxn = 1e6 + 10;
char s1[maxn], s2[maxn], s1b[maxn], s2b[maxn];
bitset<maxn> ok1, ok2;
int n;
long long ans;

int main() {
	freopen("edit.in", "r", stdin);
	freopen("edit.out", "w", stdout);
	
	int T;
	scanf("%d", &T);
	while (T--) {
		ok1.set(); ok2.set();
		ans = 0;
		scanf("%d", &n);
		scanf("%s", s1 + 1);
		scanf("%s", s2 + 1);
		scanf("%s", s1b + 1);
		scanf("%s", s2b + 1);
		for (int i = 1, j; i <= n; i++) {
			j = i - 1;
			if (s1b[i] == '0') {
				if (j >= 1) ok1[j] = false;
				ok1[i] = false;
			}
			if (s2b[i] == '0') {
				if (j >= 1) ok2[j] = false;
				ok2[i] = false;
			}
		}
		int p1 = 1, p2 = p1 + 1;
		while (p1 <= n) {
			if (s1[p1] != s2[p1]) {
				int tp1 = p1, tp2 = p2;
				bool flag = false;
				while (flag == false && tp1 <= n) {
					if (tp2 > n) break;
					if (ok1[tp1] == false) break;
					if (s1[tp1] == s1[tp2]) {
						tp1++, tp2++;
						continue;
					} else {
						swap(s1[p1], s1[tp2]);
						ans++;
						flag = true;
						break;
					}
				}
				tp1 = p1, tp2 = p2;
				while (flag == false && tp1 <= n) {
					if (tp2 > n) break;
					if (ok2[tp1] == false) break;
					if (s2[tp1] == s2[tp2]) {
						tp1++, tp2++;
						continue;
					} else {
						swap(s2[p1], s2[tp2]);
						ans++;
						flag = true;
						break;
					}
				}
			} else {
				ans++;
			}
			p1++, p2++;
		}
		printf("%lld\n", ans);
	}
	
	fclose(stdin);
	fclose(stdout);
	return 0;
}
