#include <cstdio>
#include <algorithm>
#include <vector>
#include <iostream>
using namespace std;
const int N = 1e5+5;
int T, n, a[N], b[N], t1[N], t2[N], s1[N], s2[N], ans;
int bel1[N], bel2[N], n1[N], n2[N];
struct Seg{
	int l, r, sum1, sum0;
}se1[N], se2[N];
inline void solve(){
	bool flagb = true;
	ans = 0;
	int cnt1=0, cnt2=0;
	scanf("%d", &n);
	s1[0] = s2[0] = 0;
	for(int i=1; i<=n; ++i){
		scanf("%1d", &a[i]); s1[i] = s1[i-1]+a[i];
		bel1[i] = 0;
	}
	for(int i=1; i<=n; ++i){
		scanf("%1d", &b[i]); s2[i] = s2[i-1]+b[i];
		bel2[i] = 0;
	}
	for(int i=1; i<=n; ++i) scanf("%1d", &t1[i]);
	for(int i=1; i<=n; ++i) scanf("%1d", &t2[i]);
	if(s1[n]==n || s1[n]==0){
		for(int i=1; i<=n; ++i) if(a[i] == b[i]) ++ans;
		printf("%d\n", ans); return;
	}
	for(int i=1; i<=n; ++i)
		if(t1[i] != t2[i]){
			flagb = false; break;
		}
	if(flagb){
		int l=1, r=0;
		for(int i=1; i<=n; ++i){
			if(t1[i] == 0){
				r = i-1;
				if(l <= r){
					ans += min(s1[r]-s1[l-1],s2[r]-s2[l-1]);
					ans += r-l+1-max(s1[r]-s1[l-1],s2[r]-s2[l-1]);
				}
				l = i+1;
				ans += (a[i]==b[i]);
			}
		}
		if(t1[n] == 1){
			r = n;
			if(l <= r){
				ans += min(s1[r]-s1[l-1],s2[r]-s2[l-1]);
				ans += r-l+1-max(s1[r]-s1[l-1],s2[r]-s2[l-1]);
			}
		}
		printf("%d\n", ans);
	}
	else printf("_\n");
}
int main(){
	freopen("edit.in", "r", stdin);
	freopen("edit.out", "w", stdout);
	scanf("%d", &T);
	while(T--) solve();
	fclose(stdin);
	fclose(stdout);
	return 0;
}
