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

const int N = 1e5 + 10;
char ss[N] ,st[N] ,sa[N] ,sb[N];
int s[N] ,t[N] ,a[N] ,b[N];
int cntl[N][2] ,cntr[N][2];
int prel[N] ,prer[N];

void init(int n)
{
	memset(a ,0 ,sizeof(a)) ,memset(b ,0 ,sizeof(b));
	for (int i = 1;i <= n;i++)
	{
		prel[i] = prer[i] = 0;
		cntl[i][0] = cntl[i][1] = cntr[i][0] = cntr[i][1] = 0;
		t[i] = (st[i] == '1');
		s[i] = (ss[i] == '1');
		a[i] = (sa[i] == '1');
		b[i] = (sb[i] == '1');
	}
}

void solve()
{
	int n;
	scanf("%d",&n);
	scanf("%s%s",ss + 1 ,st + 1);
	scanf("%s%s",sa + 1 ,sb + 1);
	
	init(n);
	
	for (int i = 1;i <= n;i++)
	{
		if (a[i] && a[i - 1])
			prel[i] = prel[i - 1] + 1;
		if (b[i] && b[i - 1])
			prer[i] = prer[i - 1] + 1;
		
		cntl[i - prel[i]][s[i]]++;
		cntr[i - prer[i]][t[i]]++;
	}
	
	int ans = 0;
	int l = 1 ,r = 1;
	while (l <= n && r <= n)
	{
		while (a[l] && a[l + 1])
			l++;
		while (b[r] && b[r + 1])
			r++;
		
		int x = l - prel[l] ,y = r - prer[r];
		int cov0 = min(cntl[x][0] ,cntr[y][0]) ,cov1 = min(cntl[x][1] ,cntr[y][1]);
		int cov = min(min(r - y + 1 ,l - x + 1) ,min(r - x + 1 ,l - y + 1));
		ans += cov0 + cov1;
		
		cntl[x][0] -= cov0 ,cntl[x][1] -= cov1;
		cntr[y][0] -= cov0 ,cntr[y][1] -= cov1;
		
		if (cov0 + cov1 < cov)
		{
			if (l >= r)
			{
				if (!cntl[x][0])
					cntl[x][1] -= cov - cov0 - cov1;
				else
					cntl[x][0] -= cov - cov0 - cov1;
			}
			else
			{
				if (!cntr[y][0])
					cntr[y][1] -= cov - cov0 - cov1;
				else
					cntr[y][0] -= cov - cov0 - cov1;
			}
		}
		
		if (l < r)
			l++;
		else if (r < l)
			r++;
		else
			l++ ,r++;
	}
	
	printf("%d\n",ans);
}

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