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

namespace sub1
{
	void solve(int &n, auto &s1, auto &s2)
	{
		int ans = 0;
		for (int i = 1; i <= n; i++)
		{
			if (s2[i] == s1[1])  ans++;
		}
		cout << ans << '\n';
	}
}

namespace sub2
{
	void solve(int &n, auto &s1, auto &s2, auto &t)
	{
		int ans = 0;
		vector<int> p(1, 0);
		for (int i = 1; i <= n; i++)
		{
			if (t[i] == 0)
			{
				p.push_back(i);
				if (s1[i] == s2[i])  ans++;
			}
		}
		p.push_back(n + 1);
		for (int i = 0; i < p.size() - 1; i++)
		{
			vector<int> cnt1(2), cnt2(2);
			for (int j = p[i] + 1; j <= p[i + 1] - 1; j++)
			{
				cnt1[s1[j]]++;
				cnt2[s2[j]]++;
			}
			ans += min(cnt1[0], cnt2[0]) + min(cnt1[1], cnt2[1]);
		}
		cout << ans << '\n';
	}
}

namespace sub3
{
	void solve(int &n, auto &s1, auto &s2, auto &t1, auto &t2)
	{
		int ans = 0, pos1, pos2;
		for (int i = 1; i <= n; i++)
		{
			if (t1[i] == 0)  pos1 = i;
			if (t2[i] == 0)  pos2 = i;
		}
		if (pos1 > pos2)
		{
			swap(s1, s2);
			swap(pos1, pos2);
		}
		vector<int> cntPre1(2), cntPre2(2), cntNxt1(2), cntNxt2(2), cntPreCom(2), cntNxtCom(2);
		for (int i = 1; i < pos1; i++)  cntPre1[s1[i]]++;
		for (int i = 1; i < pos2; i++)  cntPre2[s2[i]]++;
		for (int i = pos1 + 1; i <= n; i++)  cntNxt1[s1[i]]++;
		for (int i = pos2 + 1; i <= n; i++)  cntNxt2[s2[i]]++;
		if (cntNxt1[s2[pos2]] >= 1)
		{
			ans++;
			cntNxt1[s2[pos2]]--;
		}
		else  cntNxt1[!s2[pos2]]--;
		if (cntPre2[s1[pos1]] >= 1)
		{
			ans++;
			cntPre2[s1[pos1]]--;
		}
		else  cntPre2[!s1[pos1]]--;
		if (cntPre2[0] < cntPre1[0])
		{
			cntPreCom[0] = cntPre2[0];
			cntPreCom[1] = pos1 - 1 - cntPreCom[0];
		}
		else if (cntPre2[1] < cntPre1[1])
		{
			cntPreCom[1] = cntPre2[1];
			cntPreCom[0] = pos1 - 1 - cntPreCom[1];
		}
		else
		{
			cntPreCom[0] = cntPre1[0];
			cntPreCom[1] = cntPre1[1];
		}
		ans += min(cntPre1[0], cntPreCom[0]) + min(cntPre1[1], cntPreCom[1]);
		cntPre2[0] -= cntPreCom[0];
		cntPre2[1] -= cntPreCom[1];
		if (cntNxt1[0] < cntNxt2[0])
		{
			cntNxtCom[0] = cntNxt1[0];
			cntNxtCom[1] = n - pos2 - cntNxtCom[0];
		}
		else if (cntNxt1[1] < cntNxt2[1])
		{
			cntNxtCom[1] = cntNxt1[1];
			cntNxtCom[0] = n - pos2 - cntNxtCom[1];
		}
		else
		{
			cntNxtCom[0] = cntNxt2[0];
			cntNxtCom[1] = cntNxt2[1];
		}
		ans += min(cntNxt2[0], cntNxtCom[0]) + min(cntNxt2[1], cntNxtCom[1]);
		cntNxt1[0] -= cntNxtCom[0];
		cntNxt1[1] -= cntNxtCom[1];
		ans += min(cntNxt1[0], cntPre2[0]) + min(cntNxt1[1], cntPre2[1]);
		cout << ans << '\n';
	}
}

int main()
{
	freopen("edit.in", "r", stdin);
	freopen("edit.out", "w", stdout);
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	int T;
	cin >> T;
	for (int arona = 1; arona <= T; arona++)
	{
		int n;
		string tmp1, tmp2, tmp3, tmp4;
		bool flagA = 1, flagB = 1, flagC = 0;
		cin >> n;
		vector<int> s1(n + 1), s2(n + 1), t1(n + 1), t2(n + 1);
		cin >> tmp1 >> tmp2 >> tmp3 >> tmp4;
		for (int i = 1; i <= n; i++)  s1[i] = tmp1[i - 1] - '0';
		for (int i = 1; i <= n; i++)  s2[i] = tmp2[i - 1] - '0';
		for (int i = 1; i <= n; i++)  t1[i] = tmp3[i - 1] - '0';
		for (int i = 1; i <= n; i++)  t2[i] = tmp4[i - 1] - '0';
		for (int i = 1; i < n; i++)
		{
			if (s1[i] != s1[i + 1])
			{
				flagA = 0;
				break;
			}
		}
		for (int i = 1; i <= n; i++)
		{
			if (t1[i] != t2[i])
			{
				flagB = 0;
				break;
			}
		}
		int tmpCnt1 = 0, tmpCnt2 = 0;
		for (int i = 1; i <= n; i++)
		{
			if (t1[i] == 0)  tmpCnt1++;
			if (t2[i] == 0)  tmpCnt2++;
		}
		if (tmpCnt1 == 1 && tmpCnt2 == 1)  flagC = 1;
		if (flagA)  sub1::solve(n, s1, s2);
		else if (flagB)  sub2::solve(n, s1, s2, t1);
		else if (flagC)  sub3::solve(n, s1, s2, t1, t2);
		else  cout << n - 2 << '\n';
	}
	return 0;
}
