#include <bits/stdc++.h> 
using namespace std;
const int MaxN = 1e5 + 5;
int T, N, Ans, Idx1, Idx2;
int S1[MaxN], T1[MaxN];
int S2[MaxN], T2[MaxN];
int F1[MaxN][2], F2[MaxN][2];
int Block1[MaxN], Block2[MaxN];
int Lst1[MaxN], Lst2[MaxN];
void Kick(int& Val)
{
	Val = max(0, Val - 1);
}
int main()
{
	freopen("edit.in", "r", stdin);
	freopen("edit.out", "w", stdout);
	scanf("%d", &T);
	while (T--)
	{
		Ans = 0;
		scanf("%d", &N);
		memset(F1, 0, sizeof F1);
		memset(F2, 0, sizeof F2);
		for (int i = 1; i <= N; ++i)
		{
			scanf("%1d", &S1[i]);
		}
		for (int i = 1; i <= N; ++i)
		{
			scanf("%1d", &S2[i]);
		}
		for (int i = 1; i <= N; ++i)
		{
			scanf("%1d", &T1[i]);
		}
		for (int i = 1; i <= N; ++i)
		{
			scanf("%1d", &T2[i]);
		}
		Idx1 = Idx2 = 1;
		for (int i = 1; i <= N; ++i)
		{
		    if (T1[i])
		    {
		    	++F1[Idx1][S1[i]];
		    	Block1[i] = Idx1;
			}
			else
			{
			    ++Idx1;
			}
			if (T2[i])
			{
				++F2[Idx2][S2[i]];
				Block2[i] = Idx2;
			}
			else
			{
				++Idx2;
			}
		}
	    for (int i = 1; i <= N; ++i)
	    {
	    	if (T1[i] == 0 && T2[i] == 0)
	    	{
	    		Ans += S1[i] == S2[i];
	    		continue;
			}
			if (T1[i] == 1 && T2[i] == 1)
			{
				continue;
			}
			if (T1[i] == 0)
			{
				Ans += min(1, F2[Block2[i]][S1[i]]);
				Kick(F2[Block2[i]][S1[i]]);
			}
			else
			{
				Ans += min(1, F1[Block1[i]][S2[i]]);
				Kick(F1[Block1[i]][S2[i]]);
			}
		}
		for (int i = 1; i <= N; ++i)
		{
			if (T1[i] == 1 && T2[i] == 1)
			{
				if (F1[Block1[i]][0] && F2[Block2[i]][0])
			    {
			    	Kick(F1[Block1[i]][0]);
			    	Kick(F2[Block2[i]][0]);
			    	++Ans;
			    	continue;
				}
				if (F1[Block1[i]][1] && F2[Block2[i]][1])
			    {
			    	Kick(F1[Block1[i]][1]);
			    	Kick(F2[Block2[i]][1]);
			    	++Ans;
			    	continue;
				}
			}
		}
		printf("%d\n", Ans);
	}
	return 0;
}

