#include<bits/stdc++.h>
using namespace std;
int n,l1[100010],r1[100010],l2[100010],r2[100010],ct1,ct2,ma;
char s1[100010],s2[100010],t1[100010],t2[100010];
void dfs2(int x,char a[],char b[])
{
	if(x==ct2)
	{
		int res=0;
		for(int i=0;i<n;i++)res+=int(a[i]==b[i]);
		ma=max(ma,res);
		return;
	}
	int sb[20],len=0;
	for(int i=l2[x+1];i<=r2[x+1];i++)sb[++len]=a[i]-48;
	sort(sb+1,sb+1+len);
	do
	{
		for(int i=l2[x+1],j=1;i<=r2[x+1];i++,j++)a[i]=sb[j]+48;
		dfs2(x+1,a,b);
	}while(next_permutation(sb+1,sb+1+len));
}
void dfs1(int x,char a[])
{
	if(x==ct1)
	{
		dfs2(0,s2,a);
		return;
	}
	int sb[20],len=0;
	for(int i=l1[x+1];i<=r1[x+1];i++)sb[++len]=a[i]-48;
	sort(sb+1,sb+1+len);
	do
	{
		for(int i=l1[x+1],j=1;i<=r1[x+1];i++,j++)a[i]=sb[j]+48;
		dfs1(x+1,a);
	}while(next_permutation(sb+1,sb+1+len));
}
signed main()
{
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	int t;
	scanf("%d",bitand t);
	while(t--)
	{
		ct1=ct2=ma=0;
		scanf("%d",bitand n); 
		scanf("%s",s1),scanf("%s",s2),scanf("%s",t1),scanf("%s",t2);
		if(n<=10)
		{
			for(int i=0;i<n;i++)
			{
				if(t1[i]=='0')continue;
				if(t1[max(i-1,0)]=='0'||i==0)l1[++ct1]=i;
				if(t1[i+1]=='0'||i==n-1)r1[ct1]=i;
			}
			for(int i=0;i<n;i++)
			{
				if(t2[i]=='0')continue;
				if(t2[max(i-1,0)]=='0'||i==0)l2[++ct2]=i;
				if(t2[i+1]=='0'||i==n-1)r2[ct2]=i;
			}
//			for(int i=1;i<=ct1;i++)cout<<l1[i]<<" "<<r1[i]<<endl;
//			for(int i=1;i<=ct2;i++)cout<<l2[i]<<" "<<r2[i]<<endl;
			dfs1(0,s1);
			printf("%d\n",ma);
		}
		else
		{
			int jc=0,sc1=0,sc2=0;
			for(int i=0;i<n;i++)jc+=(s1[i]-48);
			if(jc==n)
			{
				for(int i=0;i<n;i++)sc1+=(s2[i]-48);
				printf("%d\n",sc1);
			}
			else if(jc==0)
			{
				for(int i=0;i<n;i++)sc2+=(s2[i]-48);
				printf("%d\n",n-sc2);
			}
			else
			{
				int bj=0;
				for(int i=0;i<n;i++)if(t1[i]!=t2[i])bj=1;
				if(bj==0)
				{
					for(int i=0;i<n;i++)
					{
						if(t1[i]=='0')continue;
						if(t1[max(i-1,0)]=='0'||i==0)l1[++ct1]=i;
						if(t1[i+1]=='0'||i==n-1)r1[ct1]=i;
					}
					int res=0;
					for(int i=1;i<=ct1;i++)
					{
						int sb1=0,sb2=0;
						for(int j=l1[i];j<=r1[i];j++)sb1+=s1[j]-48,sb2+=s2[j]-48;
						res+=min(sb1,sb2)+min(r1[i]-l1[i]+1-sb1,r1[i]-l1[i]+1-sb2);
					}
					for(int i=0;i<n;i++)if(t1[i]=='0')res+=int(s1[i]==s2[i]);
					printf("%d\n",res);
				}
			}
		}
	}
	return 0;
} 
//11:28 small goal:get 3rd prize without AC any prob in 1.5 h
//11:33 i didn't do anything in the last 3 hours 
//11:38 seems like it just not gonna happenW
//12:10 40 pts now
//12:23 60 pts now,why no toilet???
/*
/*
The thing i did in the last 3 hours
by notepad
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW
mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO
NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN
QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ
wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww
GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG
HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+++++++++++++++++++++++++++++++++++++++
=======================================
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU
DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB
PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP
KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK
#######################################
qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq
uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu
nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
ooooooooooooooooooooooooooooooooooooooo
ppppppppppppppppppppppppppppppppppppppp
ddddddddddddddddddddddddddddddddddddddd
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
ggggggggggggggggggggggggggggggggggggggg
hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh
RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR
YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY
ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS
TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
111111111111111111111111111111111111111
000000000000000000000000000000000000000
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL
???????????????????????????????????????
yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy
zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
ccccccccccccccccccccccccccccccccccccccc
vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
sssssssssssssssssssssssssssssssssssssss
***************************************
---------------------------------------
_______________________________________
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
///////////////////////////////////////
"""""""""""""""""""""""""""""""""""""""
JJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJ
rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
ttttttttttttttttttttttttttttttttttttttt
fffffffffffffffffffffffffffffffffffffff
(((((((((((((((((((((((((((((((((((((((
)))))))))))))))))))))))))))))))))))))))
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
```````````````````````````````````````
[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[
]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]
{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{
}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}
IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj
'''''''''''''''''''''''''''''''''''''''
iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii
|||||||||||||||||||||||||||||||||||||||
lllllllllllllllllllllllllllllllllllllll
:::::::::::::::::::::::::::::::::::::::
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
.......................................
*/
*/
