#include<bits/stdc++.h>
using namespace std;
int t,n;
string s1,s2,v1,v2;
int main()
{
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	scanf("%d",&t);
	while(t--)
	{
		cin>>n>>s1>>s2>>v1>>v2;
		bool l=0;
		int ans=0;
		for(int i=1;i<s1.size();i++)
			if(s1[i]!=s1[i-1])
			{
				l=1;
				break;
			}
		if(s1==s2)
		{
			printf("%d\n",n);
			continue;
		}
		if(l==0)
		{
			for(int i=0;i<s1.size();i++)
			{
				if(s1[i]==s2[i])
					ans++;
			}
			printf("%d\n",ans);
		}
		else
		{
			int p=-1,pp;
			for(int i=0;i<n;i++)
			{
				if((s1[i]=='0'||s2[i]=='0')&&s1[i]=='0') p=i;
				if((s1[i]=='0'||s2[i]=='0')&&s2[i]=='0') pp=i;
			}
			int sum=0;
			if(p<pp)
			{
				for(int i=p;i<=pp;i++)
				{
					if(v1[i]=='0')
						break;
					sum++;
				}
				for(int i=pp;i>=p;i--)
				{
					if(v2[i]=='0')
						break;
					sum++;
				}
			}
			else
			{
				for(int i=pp;i<=p;i++)
				{
					if(v2[i]=='0')
						break;
					sum++;
				}
				for(int i=p;i>=pp;i--)
				{
					if(v1[i]=='0')
						break;
					sum++;
				}
			}
			if(sum>abs(pp-p)+1)
			{
				printf("%d\n",n);
			}
			else
				printf("%d\n",n-1);
		}
	}
}
