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

const int N = 1e6 + 10;

typedef long long ll;

ll n, ans;
char s1[N], s2[N], tot1, tot2, t1[N], t2[N];
ll id1[N], id2[N], c1[N][2], c2[N][2];

int getid1(int x)
{
	return id1[x];
}

int getnum1(int x)
{
	return s1[x] - '0';
}

int getid2(int x)
{
	return id2[x];
}

int getnum2(int x)
{
	return s2[x] - '0';
}

int main()
{
	freopen("edit.in", "r", stdin);
	freopen("edit.out", "w", stdout);
	
	int T;
	cin >> T;
	while (T--)
	{
		ans = 0, tot1 = 0, tot2 = 0;
		memset(s1, 0, sizeof(s1));
		memset(s2, 0, sizeof(s2));
		memset(t1, 0, sizeof(t1));
		memset(t2, 0, sizeof(t2));
		memset(id1, 0, sizeof(id1));
		memset(id2, 0, sizeof(id2));
		memset(c1, 0, sizeof(c1));
		memset(c2, 0, sizeof(c2));
		
		
		
		cin >> n;
		cin >> s1 + 1 >> s2 + 1 >> t1 + 1 >> t2 + 1;
		
		
		for (int i = 1; i <= n; i++)
		{
			while (t1[i] == '0' && i <= n)
				i++;
			++tot1;
			while (t1[i] == '1' && i <= n)
				id1[i++] = tot1;
		}
		for (int i = 1; i <= n; i++)
		{
			while (t2[i] == '0' && i <= n)
				i++;
			++tot2;
			while (t2[i] == '1' && i <= n)
				id2[i++] = tot2;
		}
		
		for (int i = 1; i <= n; i++)
			if (id1[i])
				c1[getid1(i)][getnum1(i)]++;
		
		for (int i = 1; i <= n; i++)
			if (id2[i])
				c2[getid2(i)][getnum2(i)]++;
		
		for (int i = 1; i <= n; i++)
		{
			if (id1[i] == 0 && id2[i] == 0)
				if (s1[i] == s2[i])
					ans++;
			
			if (!id1[i] && id2[i])
				if (c2[getid2(i)][getnum1(i)])
					c2[getid2(i)][getnum1(i)]--, ans++;
			
			if (!id2[i] && id1[i])
				if (c1[getid1(i)][getnum2(i)])
					c1[getid1(i)][getnum2(i)]--, ans++;
			
			if (id1[i] && id2[i])
			{
				if (c1[getid1(i)][0] > 0 && c2[getid2(i)][0] > 0)
					c1[getid1(i)][0]--, c2[getid2(i)][0]--, ans++;
				else
				{
					if (c1[getid1(i)][1] > 0 && c2[getid2(i)][1] > 0)
						c1[getid1(i)][1]--, c2[getid2(i)][1]--, ans++;
				}
			}
		}
		cout << ans << endl;
	}
}
