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

const int N = 100010;
vector<int> v10[N],v11[N],v20[N],v21[N];
int c=0;
int co1[N],co2[N];
char s1[N],s2[N],t1[N],t2[N];
int n,t;

int main()
{
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	scanf("%d",&t);
	while(t--)
	{
		scanf("%d%s%s%s%s",&n,s1,s2,t1,t2);
		c=0;//zhe li you wang le qing ling dao zhi zui hou yi ge shu ju guo bu qu
		//I hate duo ce
		for(int i=0;i<n;i++)
		{
			if(t1[i]=='0') c++;
			else 
			{
				co1[i]=c;
				if(s1[i]=='1') v11[c].push_back(i);
				else v10[c].push_back(i); 
			}
		}
		c=0;
		for(int i=0;i<n;i++)
		{
			if(t2[i]=='0') c++;
			else 
			{
				co2[i]=c;
				if(s2[i]=='1') v21[c].push_back(i);
				else v20[c].push_back(i); 
			}
		}
		int ans=0;
		for(int i=0;i<n;i++)
		{
			if(t1[i]=='0' && t2[i]=='0')
			{
				if(s1[i]==s2[i]) ans++;
			}
			else if(t1[i]=='1' && t2[i]=='0')
			{
				if(s2[i]=='1' && !v11[co1[i]].empty())
				{
					ans++;
					v11[co1[i]].pop_back();
				}
				else if(s2[i]=='0' && !v10[co1[i]].empty())
				{
					ans++;
					v10[co1[i]].pop_back();
				}
			}
			else if(t1[i]=='0' && t2[i]=='1')
			{
				if(s1[i]=='1' && !v21[co2[i]].empty())
				{
					ans++;
					v21[co2[i]].pop_back();
				}
				else if(s1[i]=='0' && !v20[co2[i]].empty())
				{
					ans++;
					v20[co2[i]].pop_back();
				}	
			}
		}
		for(int i=0;i<n;i++)
		{
			if(t1[i]=='1' && t2[i]=='1')
			{
				if(!v11[co1[i]].empty() && !v21[co2[i]].empty())
				{
					v11[co1[i]].pop_back();v21[co2[i]].pop_back();
					ans++;
				}
				else if(!v10[co1[i]].empty() && !v20[co2[i]].empty())
				{
					v10[co1[i]].pop_back();v20[co2[i]].pop_back();
					ans++;
				}
			}
		}
		printf("%d\n",ans);
		for(int i=0;i<=c;i++) 
		{
			v10[i].clear();v11[i].clear();v20[i].clear();v21[i].clear();
		}
		for(int i=0;i<=n;i++) co1[i]=0,co2[i]=0;
		//big yang li ban tian pao bu guo qu
		//ran hou fa xian
		//mei you qing kong
		//duo ce bu qing kong,bao ling liang hang lei
		//CCF I love you kkksc03 I love you
		//NOIP2024 rp++
		//my luogu id:745358
	}
	return 0;
}
/*
1
6
011101
111010
111010
101101
*/
