#include <iostream>
#include <cstdio>
using namespace std;
const int MAXN = 2e5;
int n;
int a[MAXN];
int b[MAXN];
int ca[MAXN];
int cb[MAXN];
void read(int a[], int n)
{
	for(int i = 1; i <= n; i++)
	{
		char c = getchar();
		while(c != '0' && c != '1')
			c = getchar();
		a[i] = (c == '1');
	}
}
pair<int, int> acnt[MAXN];
pair<int, int> bcnt[MAXN];
void init(int a[], int ca[], pair<int, int> acnt[], int n)
{
	int h = 1;//块头
	for(int i = 1; i <= n; i++)
	{
		if(!ca[i])
			h = i + 1;
		else
		{
			if(!a[i])
				acnt[h].first++;
			else
				acnt[h].second++;
		}
	}
}

void solve()
{
	scanf("%d", &n);
	read(a, n);
	read(b, n);
	read(ca, n);
	read(cb, n);
	init(a, ca, acnt, n);
	init(b, cb, bcnt, n);
	int ans = 0;
	int acnt1 = 0, bcnt1 = 0;//a,b中1的数量
	int acnt0 = 0, bcnt0 = 0;
	acnt0 = acnt[1].first;
	acnt1 = acnt[1].second;
	bcnt0 = bcnt[1].first;
	bcnt1 = bcnt[1].second;
	a[n + 1] = 1, b[n + 1] = 0;
	ca[n + 1] = cb[n + 1] = 0;
	for(int i = 1; i <= n + 1; i++)
	{
		if(!ca[i] && !cb[i])
		{
			ans += min(acnt1, bcnt1);//1都凑到一起
			ans += min(acnt0, bcnt0);//0都凑到一起
			ans += a[i] == b[i];
			acnt0 = acnt[i + 1].first;
			acnt1 = acnt[i + 1].second;
			bcnt0 = bcnt[i + 1].first;
			bcnt1 = bcnt[i + 1].second;
		}
		else if(!ca[i])//只有a一个被固定了
		{
			if(a[i] == 0)
				acnt0++;
			else
				acnt1++;
				
			//现在需要bcnt0个0和bcnt1个1,先放1
			int put1 = min(acnt1, bcnt1);
			ans += put1;//放了多少个1,剩下的就都放0
			int put0 = min(acnt0, bcnt0); //要么是acnt0，要么是一个小于bcnt0的数
			ans += put0;
			bcnt1 -= put1;
			bcnt0 -= put0;
			if(bcnt0 > 0)
				bcnt0 -= acnt0 + acnt1 - put0 - put1; //补上
			else
				bcnt1 -= acnt0 + acnt1 - put0 - put1; //补上
			
			acnt0 = acnt[i + 1].first;
			acnt1 = acnt[i + 1].second;
		}
		else if(!cb[i])
		{
			if(b[i] == 0)
				bcnt0++;
			else
				bcnt1++;
			
			int put1 = min(acnt1, bcnt1);
			ans += put1;
			int put0 = min(acnt0, bcnt0); 
			ans += put0;
			acnt1 -= put1;
			acnt0 -= put0;
			if(acnt0 > 0)
				acnt0 -= bcnt0 + bcnt1 - put0 - put1; //补上
			else
				acnt1 -= bcnt0 + bcnt1 - put0 - put1; //补上

			bcnt0 = bcnt[i + 1].first;
			bcnt1 = bcnt[i + 1].second;

		}
	}

	printf("%d\n", ans);


	for(int i = 1; i <= n + 1; i++)
		acnt[i].first = acnt[i].second = bcnt[i].first = bcnt[i].second = 0; //多测不清空,亲人两行泪
}
int main()
{
	freopen("edit.in", "r", stdin);
	freopen("edit.out", "w", stdout);
	int T;
	scanf("%d", &T);
	while(T--)
		solve();
	return 0;
}
