#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <unordered_map>

//#define int long long
#define LL long long

using namespace std;
char buf[1 << 21], *p1 = buf, *p2 = buf;
char gc()
{
	if(p1 == p2){p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin);}
	return *(p1) ++;
}
LL read()
{
	LL x = 0, s = 1;
	scanf("%lld", &x); return x;
	char ch = gc();
	while(ch < '0' || ch > '9'){s = ch == '-' ? -1 : s; ch = gc();}
	while('0' <= ch && ch <= '0'){x = (x << 1ll) + (x << 3ll) + (ch ^ 48ll); ch = gc();}
	return x * s;
}

const int N = 2e5 + 10;

int n;
int s[2][N], t[2][N];

int ans;
int bel[2][N], csg[2];
struct seg{int l, r, id, c[2];}sg[2][N];

void init()
{
	memset(sg, 0, sizeof sg);
	memset(bel, 0, sizeof bel); memset(csg, 0, sizeof csg);
	csg[0] = csg[1] = 0;
	ans = 0;
}

void solve()
{
	init();
	
	scanf("%d", &n);
	string str;
	for(int o = 0; o <= 1; o ++)
	{
		cin >> str;
		for(int i = 1; i <= n; i ++){s[o][i] = str[i - 1] - '0';}
	}
	for(int o = 0; o <= 1; o ++)
	{
		t[o][0] = t[o][n + 1] = 0;
		cin >> str;
		for(int i = 1; i <= n; i ++){t[o][i] = str[i - 1] - '0';}
	}
	for(int o = 0; o <= 1; o ++)
	{
		int ct[2] = {0, 0};
		for(int i = 1; i <= n; i ++)
		{
			if(!t[o][i])
			{
				ct[0] = ct[1] = 0;
				bel[o][i] = ++ csg[o]; sg[o][csg[o]].l = sg[o][csg[o]].r = i; 
				sg[o][csg[o]].id = csg[o]; sg[o][csg[o]].c[s[o][i]] ++;
			}
			else
			{
				if(!t[o][i - 1]){csg[o] ++; sg[o][csg[o]].id = csg[o]; sg[o][csg[o]].l = i;}
				bel[o][i] = csg[o]; ct[s[o][i]] ++;
				if(!t[o][i + 1])
					{sg[o][csg[o]].r = i; sg[o][csg[o]].c[0] = ct[0]; sg[o][csg[o]].c[1] = ct[1]; ct[0] = ct[1] = 0;}
			 } 
		}
	}
	
//	for(int i = 1; i <= csg[0]; i ++)
//	{
//		seg tm = sg[0][i];
//		cout << tm.l << "," << tm.r << " = " << tm.c[0] << "," << tm.c[1] << "\n"; 
//	}

	for(int i = 1; i <= n; i ++)
	{
		for(int v = 0; v <= 1; v ++)
		{
			if(sg[0][bel[0][i]].c[v] && sg[1][bel[1][i]].c[v])
				{sg[0][bel[0][i]].c[v] --; sg[1][bel[1][i]].c[v] --; ans ++; break;}
		}
	}
	
	printf("%d\n", ans);
}

signed main()
{
	freopen("edit.in", "r", stdin);
	freopen("edit.out", "w", stdout);
	
	int tii = 1; scanf("%d", &tii);
	for(int z = 1; z <= tii; z ++){solve();}
}
