#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define fi first
#define se second
#define pb push_back
#define vi vector<int>
#define mkp make_pair
#define pii pair<int,int>
#define debug(x) cout << #x << " = " << x << "\n";

bool MemoryST;

const int N = 1e5 + 10;

int ls[N], lt[N];
int n, cnt, X[N]; 
string s1, s2, t1, t2;

void Mainsolve() {
	cin >> n >> s1 >> t1 >> s2 >> t2;
	s1 = " " + s1;
	t1 = " " + t1;
	s2 = " " + s2;
	t2 = " " + t2;
	int ns0 = 0, ns1 = 0, Ls = 0;
	int nt0 = 0, nt1 = 0, Lt = 0;
	ls[n] = n;
	lt[n] = n;
	for (int i = n - 1; i >= 1; --i) {
		if (s2[i] == '0') ls[i] = i;
		else if (s2[i + 1] == '0') ls[i] = i;
		else ls[i] = ls[i + 1]; 
		if (t2[i] == '0') lt[i] = i;
		else if (t2[i + 1] == '0') lt[i] = i;
		else lt[i] = lt[i + 1];
	}
	int ans = 0;
	for (int i = 1; i <= n; ++i) {
		if (Ls != ls[i]) {
			ns0 = 0; ns1 = 0;
			for (int j = i; j <= ls[i]; ++j)
				ns0 += (s1[j] == '0'), ns1 += (s1[j] == '1');
			Ls = ls[i];
		}
		if (Lt != lt[i]) {
			nt0 = 0; nt1 = 0;
			for (int j = i; j <= lt[i]; ++j)
				nt0 += (t1[j] == '0'), nt1 += (t1[j] == '1');
			Lt = lt[i];
		}
//		cout << ns0 << " " << nt0 << " " << ns1 << " " << nt1 << "\n";
		int p0 = min(ns0, nt0);
		int p1 = min(ns1, nt1);
		ans += p0 + p1;
		ns0 -= p0; nt0 -= p0; ns1 -= p1; nt1 -= p1;
		int d = min(Ls, Lt) - i + 1 - p0 - p1;
//		cout << d << "\n";
		if (!ns0) ns1 -= d;
		if (!ns1) ns0 -= d;
		if (!nt0) nt1 -= d;
		if (!nt1) nt0 -= d;
//		cout << i << " " << p0 << " " << p1 << "\n";
		i = min(Ls, Lt);
	}
	cout << ans << "\n";
}

bool MemoryED;

int main() {
	freopen("edit.in", "r", stdin);
	freopen("edit.out", "w", stdout);
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	
	cerr << fixed << setprecision(6) << (&MemoryST - &MemoryED) / 1024.0 / 1024.0 << "MB\n";
	
	int T; cin >> T;
	while (T--) Mainsolve();
	
	cerr << 1e3 * clock() / CLOCKS_PER_SEC << "ms\n";
	return 0;
} 
