#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5 + 9;
int t, n, a[N], b[N], a0[N], b0[N], cnta, cntb, ans;
char cha[N], chb[N];
// a,b表示到第i项01的数量, a0,b0表示下一个v1,v2中锁定的位置 
char s1[N], s2[N], v1[N], v2[N];
bool v[N]; // v用来确定该位置是否已经锁定 

inline int getans()
{
	int h = 0;
	for (int i = 1; i <= n; ++ i)
		if (cha[i] == chb[i])
			++ h;
	return h;
}
inline void dfs(int p, int sy1, int sy0, int k) // p <= n 时在a, p > n 为b 
{
	if (p > 2 * n)
	{
		ans = max(getans(), ans);
		return ;
	}
	if (p == n + 1)
	{
		k = 1;
		sy1 = b[b0[k] - 1];
		sy0 = b0[k] - 1 - sy1;
	}
	if (p <= n)
	{
		if (v1[p] == '0')
		{
			cha[p] = s1[p];
			dfs(p + 1, a[a0[k + 1] - 1], a0[k + 1] - a0[k] - 1 - a[a0[k + 1] - 1], k + 1);
		}
		if (sy1 > 0)
		{
			cha[p] = '1';
			dfs(p + 1, sy1 - 1, sy0, k);
		}
		if (sy0 > 0)
		{
			cha[p] = '0';
			dfs(p + 1, sy1, sy0 - 1, k);
		}
	}
	else
	{
		if (v2[p - n] == '0')
		{
			chb[p - n] = s2[p - n];
			dfs(p + 1, b[b0[k + 1] - 1], b0[k + 1] - b0[k] - 1 - b[b0[k + 1] - 1], k + 1);
		}
		if (sy1 > 0)
		{
			chb[p - n] = '1';
			dfs(p + 1, sy1 - 1, sy0, k);
		}
		if (sy0 > 0)
		{
			chb[p - n] = '0';
			dfs(p + 1, sy1, sy0 - 1, k);
		}
	}
}
inline void t10()
{
	ans = 0;
	if (v1[n] != '0')
		a0[++ cnta] = n + 1;
	if (v2[n] != '0')
		b0[++ cntb] = n + 1;
	dfs(1, a[a0[1] - 1], a0[1] - a0[0] - 1 - a[a0[1] - 1], 1);
	cout << ans << endl;
}
inline bool chka()
{
	for (int i = 2; i <= n; ++ i)
		if (s1[i] != s1[i - 1])
			return false;
	return true;
}
inline void ta() // 特殊a 
{
	char c = s1[1];
	int ans = 0;
	for (int i = 1; i <= n; ++ i)
		if (s2[i] == c)
			++ ans;
	cout << ans << endl;
	return ;
}
inline bool chkb()
{
	for (int i = 1; i <= n; ++ i)
		if (v1[i] != v2[i])
			return false;
	return true;
}
inline void tb() // 特殊b 
{
	int i0 = 0, ans = 0;
	for (int i = 1; i <= n; ++ i)
	{
		if (v1[i] == '1')
		{
			if (i != n)
				continue;
			int num = n - i0;
			int numa1 = a[n] - a[i0], numb1 = b[n] - b[i0];
			int numa0 = num - numa1, numb0 = num - numb1;
			ans += min(numa0, numb0) + min(numa1, numb1);
			i0 = i;
			continue;
		}
		if (s1[i] == s2[i]) ++ ans;
		int num = i - i0 - 1;
		int numa1 = a[i - 1] - a[i0], numb1 = b[i - 1] - b[i0];
		int numa0 = num - numa1, numb0 = num - numb1;
		ans += min(numa0, numb0) + min(numa1, numb1);
		i0 = i;
	}
	cout << ans << endl;
	return ;
}
inline bool chkc()
{
	int h = 0;
	for (int i = 1; i <= n; ++ i)
		if (v1[i] == '0')
			++ h;
	if (h != 1) return false;
	h = 0;
	for (int i = 1; i <= n; ++ i)
		if (v2[i] == '0')
			++ h;
	if (h != 1) return false;
	return true;
}
inline void tc() // 特殊c 
{
	int ans = 0;
	if (a0[1] <= b0[1])
	{
		int numa1 = a[a0[1] - 1], numb1 = b[b0[1] - 1];
		int numa0 = a0[1] - numa1 - 1, numb0 = b0[1] - numb1 - 1;
		ans += min(numa0, numb0) + min(numa1, numb1);
		numb1 -= min(numa1, numb1);
		numb0 -= min(numb0, numa0);
		if (s1[a0[1]] == '1')
		{
			if (numb1)
				++ ans, numb1 --;
		}
		if (s1[a0[1]] == '0')
		{
			if (numb0)
				++ ans, numb0 --;
		}
		int zancunb1 = numb1, zancunb0 = numb0;
		
		//
		
		numa1 = a[n] - a[a0[1]], numb1 = b[n] - b[b0[1]];
		numa0 = n - a0[1] - numa1, numb0 = n - b0[1] - numb1;
		ans += min(numa0, numb0) + min(numa1, numb1);
		numa1 -= min(numa1, numb1);
		numa0 -= min(numa0, numb0);
		if (s2[b0[1]] == '1')
		{
			if (numa1)
				++ ans, numa1 --;
		}
		if (s2[b0[1]] == '0')
		{
			if (numa0)
				++ ans, numa0 --;
		}
		numb1 = zancunb1, numb0 = zancunb0;
		int wz = b0[1] - a0[1] - 1;
		ans += min(wz, min(numa0, numb0) + min(numa1, numb1));
	}
	if (a0[1] > b0[1])
	{
		int numa1 = a[a0[1] - 1], numb1 = b[b0[1] - 1];
		int numa0 = a0[1] - numa1 - 1, numb0 = b0[1] - numb1 - 1;
		ans += min(numa0, numb0) + min(numa1, numb1);
		numa1 -= min(numa1, numb1);
		numa0 -= min(numb0, numa0);
		if (s1[b0[1]] == '1')
		{
			if (numa1)
				++ ans, numa1 --;
		}
		if (s1[b0[1]] == '0')
		{
			if (numa0)
				++ ans, numa0 --;
		}
		int zancuna1 = numa1, zancuna0 = numa0;
		
		//
		
		numa1 = a[n] - a[a0[1]], numb1 = b[n] - b[b0[1]];
		numa0 = n - a0[1] - numa1, numb0 = n - b0[1] - numb1;
		ans += min(numa0, numb0) + min(numa1, numb1);
		numb1 -= min(numa1, numb1);
		numb0 -= min(numa0, numb0);
		if (s2[a0[1]] == '1')
		{
			if (numb1)
				++ ans, numb1 --;
		}
		if (s1[a0[1]] == '0')
		{
			if (numb0)
				++ ans, numb0 --;
		}
		numa1 = zancuna1, numa0 = zancuna0;
		int wz = a0[1] - b0[1] - 1;
		ans += min(wz, min(numa0, numb0) + min(numa1, numb1));
	}
	cout << ans << endl;
}
inline void td() // 尝试正解 
{
	
}
int main()
{
	freopen("edit.in", "r", stdin);
	freopen("edit.out", "w", stdout);
	cin >> t;
	while (t --)
	{
		memset(a, 0, sizeof(a));
		memset(b, 0, sizeof(b));
		memset(a0, 0, sizeof(a0));
		memset(b0, 0, sizeof(b0));
		memset(v, false, sizeof(v));
		cnta = cntb = 0;
		cin >> n;
		cin >> s1 + 1;
		cin >> s2 + 1;
		cin >> v1 + 1;
		cin >> v2 + 1;
		for (int i = 1; i <= n; ++ i)
		{
			if (v1[i] == '1')
				a[i] = a[i - 1] + (s1[i] - '0');
			else 
				a0[++ cnta] = i;
		}
		for (int i = 1; i <= n; ++ i)
		{
			if (v2[i] == '1')
				b[i] = b[i - 1] + (s2[i] - '0');
			else b0[++ cntb] = i;
		}
		if (n <= 10)
			t10();
		else if (chka())
			ta();
		else if (chkb())
			tb();
		else if (chkc())
			tc();
		else
			td();
	}
	return 0;
}
