#include <bits/stdc++.h>
using namespace std;
#define int long long
#define MAXN 200005

int t, n;
string sx, sy, tx, ty;
int v[MAXN], fx[MAXN], fy[MAXN]; pair<int, int> szx[MAXN], szy[MAXN];

int fdx(int x){if (!x) return 0; return x == fx[x] ? x : fx[x] = fdx(fx[x]);}
int fdy(int x){if (!x) return 0; return x == fy[x] ? x : fy[x] = fdy(fy[x]);}
pair<int, int> merge(pair<int, int> x, pair<int, int> y){return {x.first+y.first, x.second+y.second};}

signed main(){
	freopen("edit.in", "r", stdin); freopen("edit.out", "w", stdout);
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	
	for (cin >> t; t; --t){
		cin >> n >> sx >> sy >> tx >> ty; sx = ' ' + sx; sy = ' ' + sy; tx = ' ' + tx; ty = ' ' + ty;
//		cerr << "YYX\n";
		sx += '0'; sy += '1'; tx += '0'; ty += '0'; ++n;
		iota(fx+1, fx+n+1, 1); iota(fy+1, fy+n+1, 1);
		for (int i(1); i<=n; ++i){
			if (sx[i] == '0') szx[i] = {1, 0}; else szx[i] = {0, 1};
			if (sy[i] == '0') szy[i] = {1, 0}; else szy[i] = {0, 1};
			if (tx[i] == '0') szx[i] = {0, 0}; if (ty[i] == '0') szy[i] = {0, 0};
		}
		for (int i(1); i<n; ++i){
			if (tx[i] == '1' && tx[i+1] == '1') szx[i+1] = merge(szx[i+1], szx[i]), fx[i] = i+1;
			if (ty[i] == '1' && ty[i+1] == '1') szy[i+1] = merge(szy[i+1], szy[i]), fy[i] = i+1;
		}
//		cout << szy[9].second << ' '<< fdy(9) << '\n';
//		auto p(szy[fdy(5)]); cout << p.first << ' ' << p.second << '\n';
		for (int i(1); i<=n; ++i){
			if (tx[i] == '0' && ty[i] == '0') v[i] = 3;
			else if (tx[i] == '0') v[i] = 2; else if (ty[i] == '0') v[i] = 1; else v[i] = 0;
		}
//		cerr << "QYY\n" << t << '\n';
		int ans(0);
		for (int i(1); i<=n; ++i){
//			if (t == 3) cerr << i << ' ' << v[i] << '\n';
			if (v[i] == 1){
//				if (t == 3) cerr << "QYY" << ' ' << fdy(i-1) << ' ' << szy[fdy(i-1)].first << ' ' << szy[fdy(i-1)].second << '\n';
				auto p(merge(szy[fdy(i-1)], sy[i] == '0' ? pair<int, int>{1, 0} : pair<int, int>{0, 1}));
				auto &pt(szx[fdx(i)]);
//				if (i == 8) cout << p.first << ' ' << p.second << ' ' << pt.first << ' ' << pt.second << '\n';
//				if (t == 3) cerr << pt.first << '\n';
				if (pt.first < p.first) pt.second -= p.first-pt.first+p.second, ans += pt.first+p.second, pt.first = 0;
				else if (pt.second < p.second) pt.first -= p.second-pt.second+p.first, ans += pt.second+p.first, pt.second = 0;
				else pt.first -= p.first, pt.second -= p.second, ans += p.first+p.second;
			}else if (v[i] == 2){
				auto p(merge(szx[fdx(i-1)], sx[i] == '0' ? pair<int, int>{1, 0} : pair<int, int>{0, 1})); auto &pt(szy[fdy(i)]);
//				if (i == 7) cout << "k:" << pt.first << ' ' << pt.second << ' ' << p.first << ' ' << p.second << '\n';
				if (pt.first < p.first) pt.second -= p.first-pt.first+p.second, ans += pt.first+p.second, pt.first = 0;
				else if (pt.second < p.second) pt.first -= p.second-pt.second+p.first, ans += pt.second+p.first, pt.second = 0;
				else pt.first -= p.first, pt.second -= p.second, ans += p.first+p.second;
//				if (i == 7) cout << "k:" << pt.first << ' ' << pt.second << ' ' << p.first << ' ' << p.second << '\n';
			}else if (v[i] == 3){
				auto px(szx[fdx(i-1)]), py(szy[fdy(i-1)]);
				ans += min(px.first, py.first)+min(px.second, py.second)+(sx[i] == sy[i]);
//				cout << px.first << ' ' << px.second << ' ' << py.first << ' ' << py.second << '\n';
			}
//			auto p(szy[fdy(2)]); cout << "g:" << p.first << ' ' << p.second << '\n';
//			cout << i << ' ' << ans << '\n';
		}
		cout << ans << '\n';
	}
	
	return 0;
}

/*
1
10
0110111100
1111111100
1110000100
0110111011
*/

