#include <iostream>
#include <cstring>
using namespace std;
int T,n,cnt1[100005],cnt2[100005],ans;
string a,b,s,t;
char x[100005],y[100005];
void dfs(int pos)
{
	if (pos==n)
	{
		int num1=0,num2=0;
		for (int i=0;i<n;i++)
		{
			if (x[i]=='1') num1++;
			if (y[i]=='1') num2++;
			if (s[i]=='0'&&(x[i]!=a[i]||num1!=cnt1[i])) return;
			if (t[i]=='0'&&(y[i]!=b[i]||num2!=cnt2[i])) return;
		}
		if (num1!=cnt1[n-1]||num2!=cnt2[n-1]) return;
		int temp=0;
		for (int i=0;i<n;i++)
			if (x[i]==y[i])
				temp++;
		ans=max(ans,temp);
		return;
	}
	x[pos]='0';
	y[pos]='1';
	dfs(pos+1);
	x[pos]='0';
	y[pos]='0';
	dfs(pos+1);
	x[pos]='1';
	y[pos]='1';
	dfs(pos+1);
	x[pos]='1';
	y[pos]='0';
	dfs(pos+1);
	return;
}
inline void solve1()
{
	ans=0;
	dfs(0);
	cout<<ans<<endl;
}
inline void solve2()
{
	cout<<(a[0]=='1'?cnt2[n-1]:n-cnt2[n-1])<<endl;
}
int main()
{
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	cin>>T;
	while (T--)
	{
		cin>>n>>a>>b>>s>>t;
		cnt1[0]=(a[0]=='1'?1:0);
		cnt2[0]=(b[0]=='1'?1:0);
		for (int i=1;i<n;i++)
		{
			cnt1[i]=cnt1[i-1];
			cnt2[i]=cnt2[i-1];
			if (a[i]=='1') cnt1[i]++;
			if (b[i]=='1') cnt2[i]++;
		}
		if (n<=10) solve1();
		else solve2();
	}
	return 0;
} 
