#include<stdio.h>//40
#include<iostream>
#include<string>
using namespace std;
int T,n,cnt1,cnt2,ans;
string s1,s2,t1,t2;
bool flag1,flag2;
int main()
{
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	ios::sync_with_stdio(false);
	cin>>T;
	while(T--)
	{
		cin>>n>>s1>>s2>>t1>>t2;
		ans=cnt1=cnt2=0;
		flag2=false;
		flag1=true;
		for(int i=0;i<n;i++)
		{
			if(s1[i]!=s1[0])
			{
				flag1=false;
				break;
			}
		}
		for(int i=0;i<n;i++)
		{
			if(t1[i]=='0')
			{
				cnt1++;
			}
		}
		for(int i=0;i<n;i++)
		{
			if(t2[i]=='0')
			{
				cnt2++;
			}
		}
		if(flag1==true)
		{
			for(int i=0;i<n;i++)
			{
				if(s1[i]==s2[i])
				{
					ans++;
				}
			}
			cout<<ans<<endl;
		}
		else if(t1==t2)
		{
			for(int l=0;l<n;l++)
			{
				int r=l;
				if(t1[l]=='0')
				{
					ans+=(s1[l]==s2[l]);
				}
				else
				{
					cnt1=cnt2=0;
					while(r+1<n&&t1[r+1]=='1')
					{
						cnt1+=(s1[r]=='0');
						cnt2+=(s2[r]=='0');
						r++;
					}
					cnt1+=(s1[r]=='0');
					cnt2+=(s2[r]=='0');
					ans+=min(cnt1,cnt2)+min(r-l+1-cnt1,r-l+1-cnt2);
					l=r;
				}
			}
			cout<<ans<<endl;
		}
		else
		{
			cout<<ans<<endl;
		}
	}
	return 0;
}
