#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
int s1[maxn], s2[maxn],sum1[maxn], sum2[maxn];
char t1[maxn], t2[maxn];
int t, n;
int main()
{
	freopen("edit.in", "r", stdin);
	freopen("edit.out", "w", stdout);
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> t;
	while(t--)
	{
		cin >> n;
		for(int i = 1; i <= n; i++)
		{
			char x;
			cin >> x;
			s1[i] = x - '0';
			sum1[i] = sum1[i - 1] + s1[i];
		}
		for(int i = 1; i <= n; i++)
		{
			char x;
			cin >> x;
			s2[i] = x - '0';
			sum2[i] = sum2[i - 1] + s2[i];
		}
		cin >> (t1 + 1);
		cin >> (t2 + 1);
		int ans = 0;
		if(t1 == t2)
		{
			int cnt1 = 0, cnt2 = 0, cnt3 = 0, cnt4 = 0;
			for(int i = 1; i <= n; i++)
			{
				if(t1[i] == 0)
				{
					if(s1[i] == s2[i])
					{
						ans++;
					}
					ans = ans + min(cnt1, cnt3) + min(cnt2, cnt4);
					cnt1 = cnt2 = cnt3 = cnt4 = 0;
				}
				else
				{
					if(s1[i] == 1) cnt2++;
					else cnt1++;
					if(s2[i] == 1) cnt4++;
					else cnt3++;
				}
			}
		}
		else if(sum1[n] == 0 || sum1[n] == n)
		{
			for(int i = 1; i <= n; i++)
			{
				if(s1[i] == s2[i]) ans++;
			}
		}
		cout << ans << '\n';
	}
	return 0;
}
