#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
#define gc getchar
#define pb push_back
#define abs_(x) max(x,-(x))
#define all(x) x.begin(),x.end()
#define y1 __
#define For(i,a,b) for(int i=(a);i<=(b);i++)
#define dFor(i,a,b) for(int i=(a);i>=(b);i--)
#define tomin(x,y) x=min(x,y)
#define tomax(x,y) x=max(x,y)
const int N=1e5+5;
int read()
{
	int x=0; int y=1; char c=gc();
	for(;!isdigit(c);c=gc()) if(c=='-') y=0;
	for(;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^48);
	return y?x:-x; 
}
int getc()
{
	char c=gc();
	for(;!isdigit(c);c=gc()) ;
	return c-'0';
}
int n;
int a[N],b[N],c[N],d[N];
struct _N
{
	int l,r,s0;
}h[N],h2[N];
int ct,ct2;
int ans=0;
void solve(int s0,int s1,int &s2,int s3)
{
	s1-=s0; s3-=s2;
//	cout<<s0<<" "<<s1<<" "<<s2<<" "<<s3<<endl;
	ans+=min(s0,s2)+min(s1,s3);
	int t=s2+s3-s0-s1;
	s2-=min(s0,s2)+max(0,s1-s3);
	if(s2>t||s2<0) exit(-1);
}
void solve2(int x,int &y,int z)
{
	if(x==0)
	{
		if(y) ans++,y--;
	}
	else
	{
		if(z-y) ans++;
		else y--;
	}
}
void pre(_N *h,int &ct,int *a,int *c)
{
	int las=0,nw=0;
	For(i,1,n+1)
	{
		if(c[i]==1) nw+=(a[i]==0);
		else
		{
			h[++ct]=(_N){las,i,nw};
			nw=0; las=i;
		}
	}
}
int work()
{
	n=read();
	For(i,1,n) a[i]=getc();
	For(i,1,n) b[i]=getc();
	For(i,1,n) c[i]=getc();
	For(i,1,n) d[i]=getc();
	ct=ct2=0;
	c[n+1]=d[n+1]=0;
	a[n+1]=0; b[n+1]=1;
	pre(h,ct,a,c);
	pre(h2,ct2,b,d);
	int las=0; ans=0;
	for(int i=1,j=1;i<=ct;)
	{
		if(h[i].r<=h2[j].r)
		{
			solve(h[i].s0,h[i].r-las-1,
			h2[j].s0,h2[j].r-las-1);
			las=h[i].r;
			if(h[i].r==h2[j].r)
			{
				ans+=a[h[i].r]==b[h2[j].r];
				j++;
			}
			else
			{
				solve2(a[h[i].r],h2[j].s0,h2[j].r-las);
			}
			i++;
		}
		else
		{
			solve(h2[j].s0,h2[j].r-las-1,
			h[i].s0,h[i].r-las-1);
			las=h2[j].r;
			solve2(b[h2[j].r],h[i].s0,h[i].r-las);
			j++;
		}
	}
	return ans;
}
int main()
{
//	freopen("edit2.in","r",stdin);
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	int T=read();
	while(T--) printf("%d\n",work());
	return 0;
}


/*
just tan xin
dang qian bu pi pei , liu dao hou mian,mei bi yao

9:43 dyl
*/







