#include<iostream>
#include<cstring>
#include<cstdio>
#include<string>
namespace io
{
	void read()
	{
		return;
	}
	template<typename nowtype,typename ...nexttype>
	void read(nowtype &now,nexttype &...next)
	{
		now=0;
		char c=getchar();
		int n(1);
#define isdigit(c) ((c)>='0'&&(c)<='9')
		while(!isdigit(c)){if(c=='-') n=-1;c=getchar();}
		while(isdigit(c)){now=(now<<1)+(now<<3)+(c^48);c=getchar();}
		now*=n;
#undef isdigit
		read(next...);
	}
}
using namespace io;
namespace SOLVE
{
	typedef long long ll;
	typedef unsigned long long ull;
	const int const1=2e6+10;
	int i,l,r,ans,up1,down1,up0,down0;
	bool s1[const1],s2[const1],t1[const1],t2[const1];
	void solve()
	{
		read(l);
		bool task2(true),task3(true),task4(true);
		int upt0(0),upp(0),downt0(0),downp(0);
		ans=0;
		up1=0;
		down1=0;
		up0=0;
		down0=0;
		r=0;
		for(i=1;i<=l;++i) s1[i]=(getchar()=='1');getchar();
		for(i=1;i<=l;++i) s2[i]=(getchar()=='1');getchar();
		for(i=1;i<=l;++i) t1[i]=(getchar()=='1');getchar();
		for(i=1;i<=l;++i) t2[i]=(getchar()=='1');getchar();
		for(i=2;i<=l;++i) if(s1[i]!=s1[i-1]){task2=false;break;}
		for(i=1;i<=l;++i) if(t1[i]!=t2[i]){task3=false;break;}
		for(i=1;i<=l;++i)
		{
			if(t1[i]==0) ++upt0,upp=i;
			if(t2[i]==0) ++downt0,downp=i;
			if(upt0>1||downt0>1){task4=false;break;}
		}
		for(i=1;i<=l;++i)
		{
			if(t1[i]&&!t1[i-1]&&!t1[i+1]) t1[i]=false;
			if(t2[i]&&!t2[i-1]&&!t2[i+1]) t2[i]=false;
		}
		if(task2)
		{
			for(i=1;i<=l;++i) if(s1[i]==s2[i]) ++ans;
			printf("%d\n",ans);
			return;
		}
		if(task3)
		{
			for(i=1;i<=l;++i)
			{
				if(t1[i])
				{
					if(s1[i]) ++up1;
					else ++up0;
					if(s2[i]) ++down1;
					else ++down0;
				}
				else
				{
					if(s1[i]==s2[i]) ++ans;
					ans+=std::min(up1,down1)+std::min(up0,down0);
					up1=0;
					up0=0;
					down1=0;
					down0=0;
				}
			}
			ans+=std::min(up1,down1)+std::min(up0,down0);
			printf("%d\n",ans);
			return;
		}
		if(task4)
		{
			if(upp>downp) std::swap(s1,s2);
			if(s1[upp]) ++up1;
			else ++up0;
			for(i=1;i<upp;++i)
			{
				if(s1[i]) ++up1;
				else ++up0;
			}
			for(i=1;i<downp;++i)
			{
				if(s2[i]) ++down1;
				else ++down0;
			}
			ans+=std::max(0,down0-up0);
			down0=std::max(0,down0-up0);
			ans+=std::max(0,down1-up1);
			down1=std::max(0,down1-up1);
			up0=up1=0;
			if(s2[downp]) ++down1;
			else ++down0;
			for(i=upp+1;i<=l;++i)
			{
				if(s1[i]) ++up1;
				else ++up0;
			}
			ans+=std::max(0,up0-down0);
			up0=std::max(0,up0-down0);
			ans+=std::max(0,up1-down1);
			up1=std::max(0,up1-down1);
			for(i=downp+1;i<=l;++i)
			{
				if(s2[i]) ++down1;
				else ++down0;
			}
			ans+=std::max(0,up0-down0)+std::max(0,up1-down1);
			printf("%d\n",ans);
			return;
		}
		for(i=0;i<l;++i)
		{
			if(s1[i]==s2[i])
			{
				++ans;
				continue;
			}
			if(s1[i]!=s2[i]&&!t1[i]&&!t2[i]) continue;
			s1[r]=s1[i];
			s2[r]=s2[i];
			t1[r]=t1[i];
			t2[r]=t2[i];
			++r;
		}
		for(i=0;i<r;++i)
		{
			if(t1[i]&&s1[i]) ++up1;
			if(t1[i]&&!s1[i]) ++up0;
			if(t2[i]&&s2[i]) ++down1;
			if(t2[i]&&!s2[i]) ++down0;
		}
		for(i=0;i<r;++i)
		{
			if(t1[i]!=t2[i])
			{
				if(t1[i])
				{
					if(s2[i]&&up1>0) --up1,++ans;
					if(!s2[i]&&up0>0) --up0,++ans;
				}
				if(t2[i])
				{
					if(s1[i]&&down1>0) --down1,++ans;
					if(!s1[i]&&down0>0) --down0,++ans;
				}
			}
		}
		for(i=0;i<r;++i)
		{
			if(t1[i]==t2[i])
			{
				if(up0>0&&down0>0) --up0,--down0,++ans;
				else if(up1>0&&down1>0) --up1,--down1,++ans;
			}
		}
		printf("%d\n",ans);
	}
}
int main()
{
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	int t;
	read(t);
	while(t--) SOLVE::solve();
	fclose(stdin);
	fclose(stdout);
	return 0;
}
