#include <bits/stdc++.h>
#define fi first
#define endl '\n'
#define il inline
#define se second
#define pb push_back
#define INF 0x3f3f3f3f
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int N = 1e5 + 10;
int n, ans, acnt, bcnt, cnt[2][2];
char s1[N], s2[N], t1[N], t2[N];
pii a[N], b[N];
signed main()
{
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	freopen("edit.in", "r", stdin);
	freopen("edit.out", "w", stdout);
	int T;
	cin >> T;
	while (T--)
	{
		cin >> n >> s1 + 1 >> s2 + 1 >> t1 + 1 >> t2 + 1, ans = cnt[0][0] = cnt[1][0] = cnt[0][1] = cnt[1][1] = acnt = bcnt = 0;
		for (int i = 1; i <= n; i++)
		{
			if (t1[i] == '1') cnt[0][s1[i] == '1']++;
			else a[++acnt] = {cnt[0][0], cnt[0][1]}, a[++acnt] = {s1[i] == '0', s1[i] == '1'}, cnt[0][0] = cnt[0][1] = 0;
			if (t2[i] == '1') cnt[1][s2[i] == '1']++;
			else b[++bcnt] = {cnt[1][0], cnt[1][1]}, b[++bcnt] = {s2[i] == '0', s2[i] == '1'}, cnt[1][0] = cnt[1][1] = 0;
		}
		if (t1[n] == '1') a[++acnt] = {cnt[0][0], cnt[0][1]};
		if (t2[n] == '1') b[++bcnt] = {cnt[1][0], cnt[1][1]};
		for (int i = 1, j = 1, posa = a[1].fi + a[1].se, posb = b[1].fi + b[1].se, f1 = 1, f2 = 1; i <= acnt && j <= bcnt;)
		{
			if (posa < posb)
			{
				int len = posa - f2 + 1;
				int x = a[i].fi, y = a[i].se;
				a[i].fi = max(a[i].fi - min(b[j].fi, len), 0), a[i].se = max(a[i].se - min(b[j].se, len), 0);
				ans += x - a[i].fi + y - a[i].se;
				b[j].fi -= x - a[i].fi, b[j].se -= y - a[i].se;
			}
			else
			{
				int len = posb - f1 + 1;
				int x = b[j].fi, y = b[j].se;
				b[j].fi = max(b[j].fi - min(a[i].fi, len), 0), b[j].se = max(b[j].se - min(a[i].se, len), 0);
				ans += x - b[j].fi + y - b[j].se;
				a[i].fi -= x - b[j].fi, a[i].se -= y - b[j].se;	
			}
			if (posa > posb) j++, f2 = posb + 1, posb += b[j].fi + b[j].se;
			else if (posa < posb) i++, f1 = posa + 1, posa += a[i].fi + a[i].se;
			else i++, j++, f1 = posa + 1, f2 = posb + 1, posa += a[i].fi + a[i].se, posb += b[j].fi + b[j].se;
		}
		cout << ans << endl;
	}
	return 0;
}
