#include <iostream>
#include <vector>
using namespace std;
const int MAXN = 1e5 + 5;
struct node
{
	int l,r,c0,c1;
}a[MAXN],b[MAXN];
char s[MAXN],t[MAXN],x[MAXN],y[MAXN];
vector <int> vec;
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	int T,n,L,cnt0,cnt1,tota,totb,del,ans,lim;
	char ch;
	cin >> T;
	while (T--)
	{
		cin >> n;
		for (int i = 1; i <= n; i++) cin >> s[i];
		for (int i = 1; i <= n; i++) cin >> t[i];
		for (int i = 1; i <= n; i++) cin >> x[i];
		for (int i = 1; i <= n; i++) cin >> y[i];
		x[n + 1] = y[n + 1] = '0';
		cnt0 = cnt1 = tota = totb = ans = 0,L = 1;
		for (int i = 1; i <= n + 1; i++)
		{
			ch = x[i];
			if (ch == '1')
			{
				if (s[i] == '0') cnt0++;
				else cnt1++;
			}
			else if (ch == '0')
			{
				if (L <= i - 1) a[++tota] = {L,i - 1,cnt0,cnt1};
				cnt0 = cnt1 = 0;
				if (i <= n)
				{
					if (s[i] == '0') cnt0++;
					else cnt1++;
					a[++tota] = {i,i,cnt0,cnt1};
					cnt0 = cnt1 = 0;
				}
				L = i + 1;
			}
		}
		cnt0 = cnt1 = 0,L = 1;
		for (int i = 1; i <= n + 1; i++)
		{
			ch = y[i];
			if (ch == '1')
			{
				if (t[i] == '0') cnt0++;
				else cnt1++;
			}
			else if (ch == '0')
			{
				if (L <= i - 1) b[++totb] = {L,i - 1,cnt0,cnt1};
				cnt0 = cnt1 = 0;
				if (i <= n)
				{
					if (t[i] == '0') cnt0++;
					else cnt1++;
					b[++totb] = {i,i,cnt0,cnt1};
					cnt0 = cnt1 = 0;
				}
				L = i + 1;
			}
		}
		for (int i = 1,j = 1; i <= tota; i++)
		{
			vec.clear();
			if (b[j].r < a[i].l) j++;
			while (j <= totb && b[j].l <= a[i].r)
			{
				lim = min(a[i].r,b[j].r) - max(a[i].l,b[j].l) + 1;
				del = min(a[i].c0,b[j].c0),del = min(del,lim);
				a[i].c0 -= del,b[j].c0 -= del,ans += del;
				del = min(lim - del,min(a[i].c1,b[j].c1));
				a[i].c1 -= del,b[j].c1 -= del,ans += del;
				vec.push_back(j);
				j++;
			}
			for (int k : vec)
			{
				del = min(a[i].c0,b[k].c1);
				a[i].c0 -= del,b[k].c1 -= del;
				del = min(a[i].c1,b[k].c0);
				a[i].c1 -= del,b[k].c0 -= del;
			}
			j--;
		}
		cout << ans << '\n';
	}
	return 0;
}
/*
1
6
011101
111010
111010
101101
*/
