#include<cstdio>
using namespace std;
namespace IO
{
	const int lim=1000000;
	int curin,topin,topout;
	char in[lim+100],out[lim+100];
	char get()
	{
		if(curin==topin)
		{
			curin=0;
			topin=fread(in,1,lim,stdin);
		}
		if(topin==0)
		return 0;
		return in[curin++];
	}
	void read(int &x,int l=100)
	{
		int len=1;
		char c=get();
		while(c<'0'||c>'9')
		c=get();
		x=c-'0';
		while(len<l)
		{
			c=get();
			if(c<'0'||c>'9')
			return;
			x=x*10+c-'0';
		}
	}
	void flush()
	{
		fwrite(out,1,topout,stdout);
		topout=0;
	}
	class _{public:~_(){flush();}}__;
	void put(char c)
	{
		if(topout==lim)
		flush();
		out[topout++]=c;
	}
	void print(int x)
	{
		if(x<10)
		put(x+'0');
		else
		{
			print(x/10);
			put(x%10+'0');
		}
	}
}
using IO::put;
using IO::read;
using IO::print;
int T,I,i,n,a[110000],b[110000],c[110000],d[110000],topa,topb,cnt0a[110000],cnt1a[110000],cnt0b[110000],cnt1b[110000],cnt0,cnt1,ans;
int main()
{
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	read(T);
	for(I=1;I<=T;I++)
	{
		read(n);
		for(i=1;i<=n;i++)
		read(a[i],1);
		for(i=1;i<=n;i++)
		read(b[i],1);
		for(i=1;i<=n;i++)
		read(c[i],1);
		for(i=1;i<=n;i++)
		read(d[i],1);
		topa=0;
		topb=0;
		cnt0=0;
		cnt1=0;
		for(i=1;i<=n;i++)
		{
			if(c[i]==0||c[i-1]==0)
			{
				topa++;
				cnt0a[topa]=cnt0;
				cnt1a[topa]=cnt1;
				cnt0=0;
				cnt1=0;
			}
			if(a[i]==0)
			cnt0++;
			else
			cnt1++;
		}
		topa++;
		cnt0a[topa]=cnt0;
		cnt1a[topa]=cnt1;
		cnt0=0;
		cnt1=0;
		for(i=1;i<=n;i++)
		{
			if(d[i]==0||d[i-1]==0)
			{
				topb++;
				cnt0b[topb]=cnt0;
				cnt1b[topb]=cnt1;
				cnt0=0;
				cnt1=0;
			}
			if(b[i]==0)
			cnt0++;
			else
			cnt1++;
		}
		topb++;
		cnt0a[topb]=cnt0;
		cnt1a[topb]=cnt1;
		cnt0=1;
		cnt1=1;
		ans=0;
		while(cnt0<=topa&&cnt1<=topb)
		{
			if(cnt0a[cnt0]>0&&cnt0b[cnt1]>0)
			{
				cnt0a[cnt0]--;
				cnt0b[cnt1]--;
				ans++;
			}
			else if(cnt1a[cnt0]>0&&cnt1b[cnt1]>0)
			{
				cnt1a[cnt0]--;
				cnt1b[cnt1]--;
				ans++;
			}
			else if(cnt0a[cnt0]>0&&cnt1b[cnt1]>0)
			{
				cnt0a[cnt0]--;
				cnt1b[cnt1]--;
			}
			else if(cnt1a[cnt0]>0&&cnt0b[cnt1]>0)
			{
				cnt1a[cnt0]--;
				cnt0b[cnt1]--;
			}
			else if(cnt0a[cnt0]==0&&cnt1a[cnt0]==0)
			cnt0++;
			else
			cnt1++;
		}
		print(ans);
		put('\n');
	}
	return 0;
}
