#include <bits/stdc++.h>
#define N (int)(2e5+3)
using namespace std;

int T, n;
int x, y, l, ra, rb, d, ans;
int nxta[N], nxtb[N], suma[N], sumb[N];
char a[N], b[N], ta[N], tb[N];

inline void getnxt() {
	if(ra < rb) {
		l = ra+1;
		x = suma[l];
	} else if(ra == rb) {
		l = ra+1;
		x = suma[l], y = sumb[l]; 
	} else {
		l = rb+1;
		y = sumb[l];
	}
}

inline int getnum(int i, int j, int siz) {
	return siz - (i > j ? i-j : j-i);
}

inline void init() {
	x = y = l = ra = rb = d = ans = 0;
	memset(suma, 0, sizeof(suma));
	memset(sumb, 0, sizeof(sumb));
	memset(nxta, 0, sizeof(nxta));
	memset(nxtb, 0, sizeof(nxtb));
}

inline void solve() {
	if(ra > rb) {
		d = ra - rb;
		ans += getnum(max(y, x-d), y, rb-l+1);
		x -= max(y, x-d);
	} else if(ra < rb) {
		d = rb - ra;
		ans += getnum(x, max(x, y-d), ra-l+1);
		y -= max(x, y-d);
	} else
		ans += getnum(x, y, ra-l+1); 
}

int main() {
	freopen("edit.in", "r", stdin);
	freopen("edit.out", "w", stdout);
	scanf("%d", &T);
	while(T--) {
		init();
		scanf("%d", &n);
		scanf(" %s %s %s %s", a+1, b+1, ta+1, tb+1);
		for(int i=n, lsta=n, lstb=n; i>=1; i--) {
			suma[i] = (ta[i+1] != '0' ? suma[i+1] : 0) + (a[i] == '1');
			sumb[i] = (tb[i+1] != '0' ? sumb[i+1] : 0) + (b[i] == '1');
			if(ta[i] == '0') {
				suma[i] = (a[i] == '1');
				lsta = i-1;
			} if(tb[i] == '0') {
				sumb[i] = (b[i] == '1');
				lstb = i-1;
			}
			nxta[i] = lsta, nxtb[i] = lstb;
		}
		l = 1, x = suma[1], y = sumb[1];
		while(l <= n) {
			ra = nxta[l], rb = nxtb[l];
			if(ta[l] == '0')
				ra = l;
			if(tb[l] == '0')
				rb = l;
			solve();
			getnxt();
		}
		printf("%d\n", ans);
	}
	return 0;
}

