#include<bits/stdc++.h>
using namespace std;
const int N=2e5+10;
struct node{
	int l,r;
}tmp[N],ed[N];
int idx1,idx2;
char a[N],b[N];
char t1[N],t2[N];
int cnt1[N],cnt2[N],cnt3[N],cnt4[N];
int t,n;
bool vis[N];
namespace task1{
	node tmp1[N],tmp2[N];
	int idx1,idx2;
	int s1[N],s2[N];
	void work()
	{
		idx1=idx2=0;
		int ans=0;
		int l=1;
		for(int i=1;i<=n;i++)
		{
			if(t1[i]=='0')
			{
				if(l!=i)
				{
					tmp1[++idx1]=(node){l,i-1};
					l=i+1;
					tmp1[++idx1]=(node){i,i};
				}
				else
				{
					tmp1[++idx1]=(node){i,i};
					l=i+1;
				}
			}
		}
		if(l!=n+1)
		{
			tmp1[++idx1]=(node){l,n};
		}
		l=1;
		for(int i=1;i<=n;i++)
		{
			if(t2[i]=='0')
			{
				if(l!=i)
				{
					tmp2[++idx2]=(node){l,i-1};
					l=i+1;
					tmp2[++idx2]=(node){i,i};
				}
				else
				{
					tmp2[++idx2]=(node){i,i};
					l=i+1;
				}
			}
		}
		if(l!=n+1)
		{
			tmp2[++idx2]=(node){l,n};
		}
		
//		return ;
		for(int i=0;i<(1<<n);i++)
		{
			bool flag=true;
			s1[n+1]=0,s2[n+1]=0;
			for(int j=n;j>=1;j--)
			{
				s1[j]=s1[j+1];
				s2[j]=s2[j+1];
				if(((i>>(j-1))&1)==1)s1[j]++;
				else s2[j]++;
			}
			reverse(s1+1,s1+n+1),reverse(s2+1,s2+n+1);
			for(int j=1;j<=idx1;j++)
			{
				int l=tmp1[j].l,r=tmp1[j].r;
//				cout<<cnt2[r]<<' '<<cnt1[r]<<endl;
				if(s1[r]-s1[l-1]!=cnt2[r]-cnt2[l-1])
				{
					flag=false;
					break;
				}
				if(s2[r]-s2[l-1]!=cnt1[r]-cnt1[l-1])
				{
					flag=false;
					break;
				}
			} 
			if(flag==false)continue;
			for(int k=0;k<(1<<n);k++)
			{
//				cout<<"-----"<<k<<endl;
//int k=54;
				flag=true;
				s1[n+1]=s2[n+1]=0;
				for(int j=n;j>=1;j--)
				{
					s1[j]=s1[j+1];
					s2[j]=s2[j+1];
					if(((k>>(j-1))&1)==1)s1[j]++;
					else s2[j]++;
				}
				reverse(s1+1,s1+n+1),reverse(s2+1,s2+n+1);
				for(int j=1;j<=idx2;j++)
				{
					int l=tmp2[j].l,r=tmp2[j].r;
					if(s1[r]-s1[l-1]!=cnt4[r]-cnt4[l-1])
					{
						
						flag=false;
						break;
					}
					if(s2[r]-s2[l-1]!=cnt3[r]-cnt3[l-1])
					{
//						cout<<"here"<<endl;
						flag=false;
						break;
					}
				}
				if(flag==false)continue;
//				cout<<"----------"<<k<<endl;
//				continue;
				int res=0;
				for(int j=1;j<=n;j++)
				{
					if((i>>(j-1)&1)==(k>>(j-1)&1))
					{
						res++;
					}
				}
				ans=max(ans,res);
			}
		}
		cout<<ans<<endl;
	}
}
void init()
{
	memset(vis,0,sizeof vis);
	memset(cnt1,0,sizeof cnt1);
	memset(cnt2,0,sizeof cnt2);
	memset(cnt3,0,sizeof cnt3);
	memset(cnt4,0,sizeof cnt4);
}
int main()
{
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	cin>>t;
	while(t--)
	{
		init();
		cin>>n;
		cin>>(a+1)>>(b+1);
		cin>>(t1+1)>>(t2+1);
		bool flag=true,flag2=true;
		for(int i=1;i<n;i++)
		{
			if(a[i]!=a[i+1])flag=false;
		}
		for(int i=1;i<=n;i++)
		{
			cnt1[i]=cnt1[i-1];
			cnt2[i]=cnt2[i-1];
			if(a[i]=='0')cnt1[i]++;
			else cnt2[i]++;
			if(t1[i]!=t2[i])flag2=false;
		}
		for(int i=1;i<=n;i++)
		{
			cnt3[i]=cnt3[i-1];
			cnt4[i]=cnt4[i-1];
			if(b[i]=='0')cnt3[i]++;
			else cnt4[i]++;
		}
		if(n<=10)
		{
			task1::work();
			continue;	
		} 
		if(flag==true)
		{
			int ans=0;
			for(int i=1;i<=n;i++)
			{
				if(a[i]==b[i])ans++; 
			}
			cout<<ans<<endl;
			continue;
		}
		int l=1;
		for(int i=1;i<=n;i++)
		{
			if(t1[i]=='0')
			{
				vis[i]=1;
			}
			if(t2[i]=='0')
			{
				vis[i]=1;
			}
		}
		for(int i=1;i<=n;i++)
		{
			if(vis[i]==1)
			{
				if(l!=i)
				{
					tmp[++idx1]=(node){l,i-1};
					l=i+1;
					tmp[++idx1]=(node){i,i};
				}
				else
				{
					tmp[++idx1]=(node){i,i};
					l=i+1;
				}
			}
		}
		if(l!=n+1)
		{
			tmp[++idx1]=(node){l,n};
		}
//		for(int i=1;i<=idx1;i++)cout<<tmp[i].l<<' '<<tmp[i].r<<endl;
//		cout<<endl;
//		
		if(flag2==true)
		{
			int ans=0;
			for(int i=1;i<=idx1;i++)
			{
				int l=tmp[i].l,r=tmp[i].r;
				int x=cnt1[r]-cnt1[l-1];
				int y=cnt3[r]-cnt3[l-1];
				int c=cnt2[r]-cnt2[l-1];
				int d=cnt4[r]-cnt4[l-1];
				ans+=min(x,y)+min(c,d);
			}
			cout<<ans<<endl;
		}
	}
	return 0;
}

