#include<iostream>
#include<cmath>
using namespace std;
const int MAXN=1e5+100;
char s1[MAXN],s2[MAXN],t1[MAXN],t2[MAXN];
bool fa,fb;
int fcnt,t1pos,t2pos,ans;
int T,Told,n;
void rread()
{
	cin>>n;
	ans=0;
	int tmp=scanf("%s%s%s%s",s1,s2,t1,t2);
		fa=fb=true;
		fcnt=0;
		for(int i=1;i<n;i++)
		{
			if(s1[i-1]!=s1[i])
			{
				fa=false;
				break;
			}
		}
		for(int i=0;i<n;i++)
		{
			if(t1[i]!=t2[i])
				fb=false;
			if(t1[i]=='0')
			{
				fcnt++;
				t1pos=i;
			}
			if(t2[i]=='0')
			{
				fcnt++;
				t2pos=i;
			}
		}	
}
int main()
{
	FILE *fp;
	fp=freopen("edit.in","r",stdin);
	fp=freopen("edit.out","w",stdout);
	cin>>T;
	Told=T;
	while(T--)
	{
		rread();
		if(fa)
		{
			for(int i=0;i<n;i++)
				if(s2[i]==s1[i])
					ans++;
			cout<<ans<<'\n';
		}
		else if(fb)
		{
			for(int i=0;i<n;i++)
			{
				if(t1[i]=='0')
				{
					if(s1[i]==s2[i])
						ans++;
				}
				else
				{
					int s1cnt=0,s2cnt=0,ncnt=0;
					while(t1[i]=='1'&&i<n)
					{
						s1cnt+=s1[i]-'0';
						s2cnt+=s2[i]-'0';
						i++;	
						ncnt++;
					}
					ans+=min(s1cnt,s2cnt);
					ans+=min(ncnt-s1cnt,ncnt-s2cnt);	
					i--;
				} 
			}
			cout<<ans<<'\n';
		}
		else if(fcnt==2)
		{
			int acnt1=0,acnt2=0;
			int bcnt1=0,bcnt2=0;
			for(int i=0;i<t1pos;i++)
				acnt1+=s1[i]-'0';
			for(int i=t1pos;i<n;i++)
				acnt2+=s1[i]-'0';
			for(int i=0;i<t2pos;i++)
				bcnt1+=s2[i]-'0';
			for(int i=t2pos;i<n;i++)
				bcnt2+=s2[i]-'0';
			ans+=min(acnt1,bcnt1);
			ans+=min(t1pos-acnt1,t2pos-bcnt1);
			ans+=min(acnt2,bcnt2);
			ans+=min((n-t1pos)-acnt2,(n-t2pos)-bcnt2);
			int al1=abs(acnt1-bcnt1);
			int bl1=abs(acnt2-bcnt2);
			int al0=abs((t1pos-acnt1)-(t2pos-bcnt1));
			int bl0=abs(((n-t1pos)-acnt2)-((n-t2pos)-bcnt2));
			acnt1=min(min(bl1,al1),abs(t1pos-t2pos)-1);
			acnt2=min(min(bl0,al0),abs(t1pos-t2pos)-1);
			if(t1pos==t2pos)
				ans+=(s1[t1pos]==s2[t2pos]?1:0);
			else
				ans+=min((min(bl1,al1)-acnt1)+(min(bl0,al0)-acnt2),2);
			ans+=acnt1;
			ans+=acnt2;
			cout<<ans<<'\n';
		}
		else
		{
			cout<<ans<<'\n';	
		}
		
	}
	fclose(stdin);
	fclose(stdout);
	return 0;
}
