#include <bits/stdc++.h>
#define ll long long
#define lll __int128

using namespace std;

namespace Solve
{
	const int N = 1e5;
	
	char s1[N + 5], s2[N + 5], pos1[N + 5], pos2[N + 5];
	
	void Sol()
	{
		int n;
		scanf("%d", &n);
		scanf("%s", s1 + 1);
		scanf("%s", s2 + 1);
		scanf("%s", pos1 + 1);
		scanf("%s", pos2 + 1);
		int l = 1, r = 1, ans = 0, cnt[2] = {0, 0}, sum[2] = {0, 0};
		while (l <= n || r <= n)
		{
			while (l <= n && pos1[l] != '0') ++cnt[s1[l] ^ 48], ++l;
			while (r <= n && pos2[r] != '0') ++sum[s2[r] ^ 48], ++r;
			if (l == r && l <= n)
			{
				ans += min(cnt[0], sum[0]) + min(cnt[1], sum[1]) + (s1[l] == s2[r]);
				memset(cnt, 0, sizeof cnt);
				memset(sum, 0, sizeof sum);
				++l, ++r;
			}
			else if (l < r)
			{
				ans += min(cnt[0], sum[0]) + min(cnt[1], sum[1]);
				sum[0] -= cnt[0], sum[1] -= cnt[1];
				if (sum[0] < 0) sum[1] += sum[0], sum[0] = 0;
				if (sum[1] < 0) sum[0] += sum[1], sum[1] = 0;
				if (sum[s1[l] ^ 48] > 0) --sum[s1[l] ^ 48], ++ans;
				else --sum[(s1[l] ^ 48) ^ 1];
				memset(cnt, 0, sizeof cnt);
				++l;
			}
			else
			{
				ans += min(cnt[0], sum[0]) + min(cnt[1], sum[1]);
				cnt[0] -= sum[0], cnt[1] -= sum[1];
				if (cnt[0] < 0) cnt[1] += cnt[0], cnt[0] = 0;
				if (cnt[1] < 0) cnt[0] += cnt[1], cnt[1] = 0;
				if (cnt[s2[r] ^ 48] > 0) --cnt[s2[r] ^ 48], ++ans;
				else --cnt[(s2[r] ^ 48) ^ 1];
				memset(sum, 0, sizeof sum);
				++r;
			}
		}
		printf("%d\n", ans);
	}
}

using Solve::Sol;

int main()
{
	freopen("edit.in", "r", stdin);
	freopen("edit.out", "w", stdout); 
	int t = 1;
	scanf("%d", &t);
	while (t--) Sol();
	return 0;
}
