#include<bits/stdc++.h>
using namespace std;
long long T,n;
string s1,s2;
string t1,t2;
long long answer;
struct qj
{
	long long l,r,x,y;
}sumw[100010],answ[100010];
long long sumcnt,anscnt;
bool checkA()
{
	for(int i=2;i<=n;i++)
	{
		if(s1[i]!=s1[i-1])return false;
	}
	return true;
}
int	flag[200010];
void init()
{
	for(int i=1;i<=2*n;i++)flag[i]=0;
	return;
}
void solve(long long x)
{
	init();
	long long cnt=2*n-2;
	while(x)
	{
		if(x%2==1)flag[cnt]=1;
		else flag[cnt]=0;
		cnt--;
		x/=2;
	}
	string zk=s1,tys=s2;
	for(int i=1;i<=n-1;i++)
	{
		if(flag[i]==1&&t1[i]=='1'&&t1[i+1]=='1')
		{
			swap(zk[i],zk[i+1]);
		}
	}
	for(int i=n;i<=2*n-2;i++)
	{
		if(flag[i]==1&&t2[i-n+1]=='1'&&t2[i-n+2]=='1')
		{
			swap(tys[i-n+1],tys[i-n+2]);
		}
	}
//	cout<<zk<<" "<<tys<<" ";
	long long sum=0;
	for(int i=1;i<=n;i++)
	{
		if(tys[i]==zk[i])sum++;
	}
	answer=max(answer,sum);
//	cout<<sum<<"\n";
	return;
}
int main()
{
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	cin>>T;
	while(T--)
	{
		cin>>n;
		cin>>s1>>s2>>t1>>t2;
		s1=' '+s1;
		s2=' '+s2;
		t1=' '+t1;
		t2=' '+t2;
		s1=s1+' ';
		s2=s2+' ';
		answer=0;
		if(checkA()==true)
		{
			for(int i=1;i<=n;i++)
			{
				if(s2[i]==s1[i])answer++;
			}
			cout<<answer<<"\n";
			continue;
		}
		else if(n<=10)
		{
			for(int i=0;i<=(1<<(n*2-1))-1;i++)
			{
				solve(i);
			}
			cout<<answer<<"\n";
			answer=0;
			continue;
		}
		for(int i=1;i<=n;i++)
		{
			if(t1[i]=='0'&&t2[i]=='0')
			{	
				if(s1[i]==s2[i])answer++;
			}
		}
		sumcnt=anscnt=0;
		for(int i=1;i<=n;i++)sumw[i].x=0,sumw[i].y=0,answ[i].x=0,answ[i].y=0,sumw[i].l=0,sumw[i].r=0,answ[i].l=0,answ[i].r=0;
		for(int i=1;i<=n;i++)
		{
			if(t1[i]!=t1[i-1]&&t1[i]=='1')
			{
				sumcnt++;
				sumw[sumcnt].l=i;
			}
			if(t1[i]!=t1[i+1]&&t1[i]=='1')
			{
				sumw[sumcnt].r=i;
			}
			if(t1[i]=='1'&&s1[i]=='1')sumw[sumcnt].x++;
			if(t1[i]=='1'&&s1[i]=='0')sumw[sumcnt].y++;
			if(t2[i]!=t2[i-1]&&t2[i]=='1')
			{
				anscnt++;
				answ[anscnt].l=i;
			}
			if(t2[i]!=t2[i+1]&&t2[i]=='1')
			{
				answ[anscnt].r=i;
			}
			if(t2[i]=='1'&&s2[i]=='1')answ[anscnt].x++;
			if(t2[i]=='1'&&s2[i]=='0')answ[anscnt].y++;
		}
		long long L=0;
		for(int i=1;i<=n;i++)
		{
			if(i>sumw[L].r)L++;
			if(t1[i]=='1')
			{
				if(t2[i]=='0')
				{
					if(s2[i]=='1')
					{
						if(sumw[L].x>=1)
						{
							sumw[L].x--;
							answer++;
						}
						else sumw[L].y--;
					}
					else
					{
						if(sumw[L].y>=1)
						{
							sumw[L].y--;
							answer++;
						}
						else sumw[L].x--;
					}
				}
			}
		}
		L=0;
		for(int i=1;i<=n;i++)
		{
			if(i>answ[L].r)L++;
			if(t2[i]=='1')
			{
				if(t1[i]=='0')
				{
					if(s1[i]=='1')
					{
						if(answ[L].x>=1)
						{
							answ[L].x--;
							answer++;
						}
						else answ[L].y--;
					}
					else
					{
						if(answ[L].y>=1)
						{
							answ[L].y--;
							answer++;
						}
						else answ[L].x--;
					}
				}
			}
		}
//		cout<<answer<<" ";
////		cout<<sumcnt<<" "<<anscnt<<"\n";
//		for(int i=1;i<=sumcnt;i++)cout<<sumw[i].l<<" "<<sumw[i].r<<" "<<sumw[i].x<<" "<<sumw[i].y<<"\n";
//		cout<<"\n";
//		for(int i=1;i<=anscnt;i++)cout<<answ[i].l<<" "<<answ[i].r<<" "<<answ[i].x<<" "<<answ[i].y<<"\n";
		L=0;
		long long R=0;
		for(int i=1;i<=n;i++)
		{
			if(i>answ[R].r)R++;
			if(i>sumw[L].r)L++;
			if(t1[i]==t2[i]&&t1[i]=='1')
			{
				long long tys=max(min(sumw[L].x,answ[R].x),min(sumw[L].y,answ[R].y));
				if(tys==0)
				{
					if(sumw[L].x!=0)sumw[L].x--;
					if(sumw[L].y!=0)sumw[L].y--;
					if(answ[L].x!=0)answ[R].x--;
					if(answ[L].y!=0)answ[R].y--;
					continue;
				}
				if(min(sumw[L].x,answ[R].x)>=min(sumw[L].y,answ[L].y))
				{
					sumw[L].x--;
					answ[R].x--;
					answer++;
				}
				else
				{
					sumw[L].y--;
					answ[R].y--;
					answer++;
				}
			}
		}
		cout<<answer<<"\n";
	}
	return 0;
 } 
 /*
 these problem is toooooooooooooooo difficult for me!!!!!!
 
 help
 
 father CCF give me 100 pts plzzzzzzzzzzzzzzzzzzzzzzz
 
 TYS AK NOIP I think
 my classmates AK NOIP I think 
 ZK AK NOIP I think 
 
 */
