#include <bits/stdc++.h>
#define rep(i, l, r) for (int i = l; i <= r; i ++)
#define per(i, r, l) for (int i = r; i >= l; i --)
using namespace std;

const int _ = 2e5 + 5;
int T, n;
char s[_], t[_], blk1[_], blk2[_];
int cnt[_][2][2];

struct dsu {
	int fa[_];
	void init() {
		rep(i, 1, n) fa[i] = i;
	}
	int find (int x) {
		return x == fa[x] ? x : fa[x] = find(fa[x]);
	} 
} a, b;

void Luciy() {
	cin >> n;
	cin >> s + 1;
	cin >> t + 1;
	cin >> blk1 + 1;
	cin >> blk2 + 1;
	a.init(), b.init();
	blk1[0] = blk2[0] = '0';
	rep(i, 1, n) rep(c1, 0, 1) rep(c2, 0, 1) cnt[i][c1][c2] = 0;
	rep(i, 1, n) 
		if (blk1[i] != '0' && blk1[i - 1] != '0')	
			a.fa[a.find(i)] = a.find(i - 1);
	rep(i, 1, n) 
		if (blk2[i] != '0' && blk2[i - 1] != '0')	
			b.fa[b.find(i)] = b.find(i - 1);
	rep(i, 1, n)
		cnt[a.find(i)][0][s[i] - '0'] ++,
		cnt[b.find(i)][1][t[i] - '0'] ++;
	int ans = 0;
	rep(i, 1, n) {
		int x = a.find(i), y = b.find(i);
		rep(c, 0, 1)
			if (cnt[x][0][c] && cnt[y][1][c]) {
				ans ++,
				cnt[x][0][c] --, cnt[y][1][c] --;
				break ;
			}
	}
	cout << ans << '\n';
	return ;
}
int main() {
	freopen("edit.in", "r", stdin);
	freopen("edit.out", "w", stdout);
	cin >> T;
	while (T --) 
		Luciy();
	return 0;
}
/*
1
6
011101
111010
111010
101101

*/
