//NOIP rp++
#include <bits/stdc++.h>
#define rep1(i,a,b) for (int i = (a);i <= (b);i++)
using namespace std;
const int N = 1e5 + 10;
int n;
string s1,s2,s3,s4;
struct xxx
{
	//从beg开始，到beg+x2+x2-1结束 
	int beg;
	//有x0个0 
	int x0;
	//有x1个1 
	int x1;
	//可以自由排放顺序 
};
vector<xxx> s1v,s2v;
//每个位置属于vector的那个段 
int in1[N],in2[N];
//每个位置是否已经确定 
bool ok[N];
void solve1()
{
	int ans = 0;
	//枚举s1变成的字符串
	int lmt = (1 << n) - 1;
	rep1(i,0,lmt)
	{
		//检查s1能否变成它
		bool flag1 = true;
		for (auto p : s1v)
		{
			int cnt0 = 0;
			int cnt1 = 0;
			rep1(jj,p.beg - 1,p.beg + p.x0 + p.x1 - 2)
				if (i & (1 << jj))
					cnt1++;
				else
					cnt0++;
			if (cnt0 != p.x0 || cnt1 != p.x1)
			{
				flag1 = false;
				break;
			}
		}
		if (flag1)
		{
			rep1(j,0,lmt)
			{
				//检查s1能否变成它
				bool flag2 = true;
				for (auto pp : s2v)
				{
					int cnt0 = 0;
					int cnt1 = 0;
					rep1(jj,pp.beg - 1,pp.beg + pp.x0 + pp.x1 - 2)
						if (j & (1 << jj))
							cnt1++;
						else
							cnt0++;
					if (cnt0 != pp.x0 || cnt1 != pp.x1)
					{
						flag2 = false;
						break;
					}
				}
				if (flag2)
				{
					//都可以，更新ans
					int tmpans = 0;
					rep1(jj,0,n - 1)
						if ((i & (1 << jj)) == (j & (1 << jj)))
							tmpans++;
					ans = max(ans,tmpans);
				}
			}
		}
	}
	cout << ans << '\n';
}
bool all_same()
{
	rep1(i,1,n - 1)
		if (s1[i] != s1[i + 1])
			return false;
	return true;
}
void solve2()
{
	//直接检验s2中有多少个那种字符
	int ans = 0;
	rep1(i,1,n)
		if (s1[i] == s2[i])
			ans++;
	cout << ans << '\n';
}
void solve3()
{
	int ans = 0;
	rep1(i,0,s1v.size() - 1)
	{
		auto p1 = s1v[i];
		auto p2 = s2v[i];
		int tmp1 = p1.x0 + p2.x1;
		int tmp2 = p1.x1 + p2.x0;
		int len = p1.x0 + p1.x1;
		if (tmp1 <= len)
			ans += tmp1;
		else
			ans += tmp2;
	}
	cout << ans << '\n';
}
void solve()
{
	memset(ok,0,sizeof ok);
	memset(in1,0,sizeof in1);
	memset(in2,0,sizeof in2);
	cin >> n >> s1 >> s2 >> s3 >> s4;
	s1 = ' ' + s1;
	s2 = ' ' + s2;
	s3 = ' ' + s3;
	s4 = ' ' + s4;
	s1v.clear();
	s2v.clear();
	//处理字符串，把可交换的视为一块
	//处理s1
	for (int i = 1;i <= n;)
	{
		if (s3[i] == '0')
		{
			in1[i] = s1v.size();
			if (s1[i] == '0')
				s1v.push_back({i,1,0});
			else
				s1v.push_back({i,0,1});
			i++;
		}
		else
		{
			int j = i;
			int cnt0 = 0;
			int cnt1 = 0;
			for (;j <= n && s3[j] == '1';j++)
			{
				if (s1[j] == '0')
					cnt0++;
				else
					cnt1++;
				in1[j] = s1v.size();
			}
			s1v.push_back({i,cnt0,cnt1});
			i = j;
		}
	}
	//处理s2
	for (int i = 1;i <= n;) 
	{
		if (s4[i] == '0')
		{
			in2[i] = s2v.size();
			if (s2[i] == '0')
				s2v.push_back({i,1,0});
			else
				s2v.push_back({i,0,1});
			i++;
		}
		else
		{
			int j = i;
			int cnt0 = 0;
			int cnt1 = 0;
			for (;j <= n && s4[j] == '1';j++)
			{
				if (s2[j] == '0')
					cnt0++;
				else
					cnt1++;
				in2[j] = s2v.size();
			}
			s2v.push_back({i,cnt0,cnt1});
			i = j;
		}
	}
	//特殊性质1：n<=10
	if (n <= 10)
		solve1();
	//特殊性质2：A
	else if (all_same())
		solve2();
	//特殊性质3：B
	else if (s3 == s4)
		solve3();
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	int t;
	cin >> t;
	while (t--)
		solve();
}

