#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 1e5 + 5, M = 2e5 + 5, INF = 1e18, mod = 1e9 + 7;

int n, ans, cnta1, cnta2, cntb1, cntb2;
string a, b, s, t;

void solve()
{
	cin >> n >> a >> b >> s >> t;
	if (s == t)
	{
		for (int i = 0; i < n; i++)
		{
			int j = i; cnta1 = cnta2 = cntb1 = cntb2 = 0;
			if (a[i] == '1') cnta1++;
			if (a[i] == '0') cnta2++;
			if (b[i] == '1') cntb1++;
			if (b[i] == '0') cntb2++;
			while (j + 1 < n && s[j + 1] == '1')
			{
				j++; if (s[j] == '0') break;
				if (a[j] == '1') cnta1++;
				if (a[j] == '0') cnta2++;
				if (b[j] == '1') cntb1++;
				if (b[j] == '0') cntb2++;
			}
			ans += min(cnta1, cntb1) + min(cnta2, cntb2);
			i = j;
		}
		cout << ans << endl;
		return;
	}
	for (int i = 0; i < n; i++)
		if (a[i] == b[i]) ans++;
	for (int i = 0; i < n; i++)
	{
		if (a[i] != b[i] && s[i] == '1')
		{
			if (a[i] == '1') cnta1++;
			else cnta2++;
		}
		if (a[i] != b[i] && t[i] == '1')
		{
			if (b[i] == '1') cntb1++;
			else cntb2++;
		}
	}
	ans += min(cnta1, cntb1) + min(cnta2, cntb2);
	cout << ans << endl;
}

void init()
{
	ans = cnta1 = cnta2 = cntb1 = cntb2 = 0;
}

signed main()
{
	freopen("edit.in", "r", stdin);
	freopen("edit.out", "w", stdout);
	
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	
	int Test; cin >> Test;
	while (Test--)
		init(), solve();
	
	return 0;
}

/*
1
4
1100
0011
1000
1010

Ans = 2

4

8
5
566
7928
594     624
73037   77897
900     905
40002   40001
619
66647   87080

8:45 40pts

AFO. Goodbye OI!
*/
