#include<iostream>
#include<fstream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
using namespace std;
const int N = 1e5 + 10;
#define pii pair<int , int> 
#define l first
#define r second
int T , n , ans;
pii num1[N] , num2[N];
int cnt1 , cnt2 , sn1[N] , sn2[N];
bool s1[N] , s2[N] , t1[N] , t2[N];
char c;

void init()
{
	for(int i = 1 ; i <= n + 2 ; i ++)
	{
		sn1[i] = sn2[i] = num1[i].l = num1[i].r = 
		num2[i].l = num2[i].r = 0;
	}
	cnt1 = cnt2 = ans = 0; 
}

void rd()
{
	for(int i = 1 ; i <= n ; i ++)
	{
		cin >> c;
		s1[i] = c - '0';
	}
	for(int i = 1 ; i <= n ; i ++)
	{
		cin >> c;
		s2[i] = c - '0';
	}
	for(int i = 1 ; i <= n ; i ++)
	{
		cin >> c;
		t1[i] = c - '0';
		if(i > 1 && t1[i - 1] && !t1[i - 2] && !t1[i])
			t1[i - 1] = 0;
	}
	if(t1[n] && !t1[n - 1]) t1[n] = 0;
	for(int i = 1 ; i <= n ; i ++)
	{
		cin >> c;
		t2[i] = c - '0';
		if(i > 1 && t2[i - 1] && !t2[i - 2] && !t2[i])
			t2[i - 1] = 0;
	}
	if(t2[n] && !t2[n - 1]) t2[n] = 0;
}

int main()
{
	freopen("edit.in" , "r" , stdin);
	freopen("edit.out" , "w" , stdout);
	cin >> T;
	while(T --)
	{
		cin >> n;
		init();
		rd();
		for(int i = 1 ; i <= n ; i ++)
		{
			if(t1[i])
			{
				if(!t1[i - 1])
				{
					cnt1++;
				}
				sn1[i] = cnt1;
				if(s1[i]) num1[cnt1].l ++;
				else num1[cnt1].r ++;
			}
		}
		for(int i = 1 ; i <= n ; i ++)
		{
			if(t2[i])
			{
				if(!t2[i - 1])
				{
					cnt2++;
				}
				sn2[i] = cnt2;
				if(s2[i]) num2[cnt2].l ++;
				else num2[cnt2].r ++;
			}
		}
		for(int i = 1 ; i <= n ; i ++)
		{
			if(t1[i] && t2[i])
			{
				if(num1[sn1[i]].l && num2[sn2[i]].l)
				{
					num1[sn1[i]].l--;
					num2[sn2[i]].l--;
					ans++;
					
				}else if(num1[sn1[i]].r && num2[sn2[i]].r){
					num1[sn1[i]].r--;
					num2[sn2[i]].r--;
					ans++;
				}
				continue;
			}
			if(t1[i])
			{
				if(s2[i] && num1[sn1[i]].l)
				{
					num1[sn1[i]].l--;
					ans++;
				}
				if(!s2[i] && num1[sn1[i]].r)
				{
					num1[sn1[i]].r--;
					ans++;
				}
				continue;
			}
			if(t2[i])
			{
				if(s1[i] && num2[sn2[i]].l)
				{
					ans++;
					num2[sn2[i]].l--;
				}
				if(!s1[i] && num2[sn2[i]].r)
				{
					num2[sn2[i]].r--;
					ans++;
				}
				continue;
			}
			if(s1[i] == s2[i]) ans++;
		}
		cout << ans << endl;
	}
	return 0;
}
