#include<bits/stdc++.h>
#define up(i, a, b) for(int i = (int)a; i <= (int)b; ++i)
#define dn(i, a, b) for(int i = (int)a; i >= (int)b; --i)

using namespace std;

const int MN = 1e5 + 5;

int n;
char s1[MN], s2[MN];
char t1[MN], t2[MN];
int nt1[MN], nt2[MN];

set<int> p0, p1;
set<int> q0, q1;

void solve(){
	scanf("%d%s%s%s%s", &n, s1 + 1, s2 + 1, t1 + 1, t2 + 1);
	up(i, 1, n){
		if(s1[i] == '0') p0.insert(i);
		else p1.insert(i);
	}
	up(i, 1, n){
		if(s2[i] == '0') q0.insert(i);
		else q1.insert(i);
	}
	int lt = n + 1;
	dn(i, n, 1){
		if(t1[i] == '0') lt = i;
		nt1[i] = lt;
	}
	lt = n + 1;
	dn(i, n, 1){
		if(t2[i] == '0') lt = i;
		nt2[i] = lt;
	}
	int ans = 0;
	up(i, 1, n){
		while(!p0.empty() && (*p0.begin()) <= i) p0.erase(p0.begin());
		while(!p1.empty() && (*p1.begin()) <= i) p1.erase(p1.begin());
		while(!q0.empty() && (*q0.begin()) <= i) q0.erase(q0.begin());
		while(!q1.empty() && (*q1.begin()) <= i) q1.erase(q1.begin());
		if(s1[i] == s2[i]) ans++;
		else{
			if(s1[i] == '0'){
				if(!p1.empty() && (*p1.begin()) < nt1[i]){
					auto it = p1.begin();
					p0.insert(*it);
					s1[*it] = '0';
					p1.erase(*it);
					ans++;
				}
				else if(!q0.empty() && (*q0.begin()) < nt2[i]){
					auto it = q0.begin();
					q1.insert(*it);
					s2[*it] = '1';
					q0.erase(*it);
					ans++;
				}
			}
			else{
				if(!p0.empty() && (*p0.begin()) < nt1[i]){
					auto it = p0.begin();
					p1.insert(*it);
					s1[*it] = '1';
					p0.erase(*it);
					ans++;
				}
				else if(!q1.empty() && (*q1.begin()) < nt2[i]){
					auto it = q1.begin();
					q0.insert(*it);
					s2[*it] = '0';
					q1.erase(*it);
					ans++;
				}
			}
		}
//		printf("FK: %d\n", ans);
	}
//	if(!p0.empty()) puts("DSGF");
	printf("%d\n", ans);
}

int main(){
	freopen("edit.in", "r", stdin);
	freopen("edit.out", "w", stdout);
	int T; cin >> T;
	while(T--){
		solve();
	}

/*
1
6
011101
111010
111010
101101
*/	
	return 0;
}
