#include <iostream>
using namespace std;
const int N = 1e5 + 7;

int n;
char a[N], b[N], ta[N], tb[N];

struct pas {
	int v0, v1;
};

pas av[N], bv[N];
int at, bt;

inline void solve() {
	at = bt = 0;
	cin >> n;
	cin >> (a + 1) >> (b + 1) >> (ta + 1) >> (tb + 1);
	int last0 = 0, last1 = 0;
	for(int i = 1; i <= n; ++i) {
		if(ta[i] == '0') {
			if(last0 || last1) av[++at] = {last0, last1};
			av[++at] = {a[i] == '0', a[i] == '1'};
			last0 = last1 = 0;
		} else last0 += a[i] == '0', last1 += a[i] == '1';
	}
	if(last0 || last1) av[++at] = {last0, last1};
	last0 = 0, last1 = 0;
	for(int i = 1; i <= n; ++i) {
		if(tb[i] == '0') {
			if(last0 || last1) bv[++bt] = {last0, last1};
			bv[++bt] = {b[i] == '0', b[i] == '1'};
			last0 = last1 = 0;
		} else last0 += b[i] == '0', last1 += b[i] == '1';
	}
	if(last0 || last1) bv[++bt] = {last0, last1};
	int as = 0, bs = 0, ans = 0, i = 0, j = 0;
	while(as < n || bs < n) {
		if(as == bs) {
			++i, as += av[i].v0 + av[i].v1;
		}
		if(as < bs) {
			int l = as;
			++i, as += av[i].v0 + av[i].v1;
			int t = min(as - l, bs - l);
			int w = min(av[i].v0, bv[j].v0);
			w = min(w, t);
			t -= w, av[i].v0 -= w, bv[j].v0 -= w;
			ans += w;
			
			w = min(av[i].v1, bv[j].v1);
			w = min(w, t);
			t -= w, av[i].v1 -= w, bv[j].v1 -= w;
			ans += w;
		} else {
			int l = bs;
			++j, bs += bv[j].v0 + bv[j].v1;
			int t = min(bs - l, as - l);
			int w = min(av[i].v0, bv[j].v0);
			w = min(w, t);
			t -= w, av[i].v0 -= w, bv[j].v0 -= w;
			ans += w;
			
			w = min(av[i].v1, bv[j].v1);
			w = min(w, t);
			t -= w, av[i].v1 -= w, bv[j].v1 -= w;
			ans += w;
		}
	}
	cout << ans << "\n";
}


int main() {
	freopen("edit.in", "r", stdin);
	freopen("edit.out", "w", stdout);
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	int t; cin >> t; for(; t--; ) solve();
} 
