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

struct num{
	int l, r, cnt;
};

vector<num> pos1, pos2;

int n, val1[100010], val2[100010], val3[100010], val4[100010], fin = 0;

void solve(){
	pos1.clear(), pos2.clear(), fin = 0;
	char z;
	cin >> n;
	for(int i = 1; i <= n; i++){
		cin >> z;
		val1[i] = z - '0';
		if(val1[i] == 1)
			fin++;
	}
	for(int i = 1; i <= n; i++){
		cin >> z;
		val2[i] = z - '0';
		if(val2[i] == 1)
			fin++;
	}
	for(int i = 1; i <= n; i++){
		cin >> z;
		val3[i] = z - '0';
	}
	for(int i = 1; i <= n; i++){
		cin >> z;
		val4[i] = z - '0';
	}
	int st = 1, sum = 0;
	for(int i = 1; i <= n; i++){
		if(val3[i] == 0){
			if(st <= i - 1)
				pos1.push_back({st, i - 1, sum});
			pos1.push_back({i, i, (val1[i] == 1)});
			st = i + 1, sum = 0;
		}
		else
			if(val1[i] == 1)
				sum++;
	}
	if(st <= n)
		pos1.push_back({st, n, sum});
	st = 1, sum = 0;
	for(int i = 1; i <= n; i++){
		if(val4[i] == 0){
			if(st <= i - 1)
				pos2.push_back({st, i - 1, sum});
			pos2.push_back({i, i, (val2[i] == 1)});
			st = i + 1, sum = 0;
		}
		else
			if(val2[i] == 1)
				sum++;
	}
	if(st <= n)
		pos2.push_back({st, n, sum});
	int l2 = 0, sum1 = pos1[0].cnt, sum2 = pos2[0].cnt, ans = 0;
	for(int i = 0; i < pos1.size(); i++){
		while(pos2[l2].r < pos1[i].r)
			ans += min(pos2[l2].r - max(pos2[l2].l, pos1[i].l) + 1, min(sum1, sum2)), sum1 -= min(pos2[l2].r - max(pos2[l2].l, pos1[i].l) + 1, min(sum1, sum2)), l2++, sum2 = pos2[l2].cnt;
		ans += min(pos1[i].r - max(pos2[l2].l, pos1[i].l) + 1, min(sum1, sum2));
		if(pos2[l2].r == pos1[i].r && i < pos1.size() - 1)
			l2++, sum2 = pos2[l2].cnt, sum1 = pos1[i + 1].cnt;
		else if(i < pos1.size() - 1)
			sum2 -= min(pos1[i].r - max(pos2[l2].l, pos1[i].l) + 1, min(sum1, sum2)), sum1 = pos1[i + 1].cnt;
	}
	cout << n - fin + 2 * ans << '\n';
}

signed main(){
	freopen("edit.in", "r", stdin);
	freopen("edit.out", "w", stdout);
	int t;
	cin >> t;
	for(int i = 1; i <= t; i++)
		solve();
	return 0;
} 
