#include <iostream>
#include <algorithm>
#include <cstdio>

using namespace std;

template<typename T>
inline void read(T &x)
{
	x=0;
	T w=1;
	char c=getchar();
	while(c<'0'||c>'9') w=(c=='-'?-w:w),c=getchar();
	while(c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
	x*=w;
}

const int S=100005;

struct node
{
	int l,r,c1,c0;
};

int n;
char a[S],b[S];
char ta[S],tb[S];
int m;
node tmp[S];

inline void slove()
{
	read(n);
	scanf("%s%s%s%s",a+1,b+1,ta+1,tb+1);
	ta[0]=ta[n+1]=tb[0]=tb[n+1]='0';
	int ans=0;
	m=0;
	for(int i=1;i<=n;i++) if(ta[i]=='0'&&tb[i]=='0') ans+=a[i]==b[i];
	for(int l=1;l<=n;l++)
	{
		if(ta[l]=='1')
		{
			int c1=0;
			int r=l;
			while(r<=n&&ta[r]=='1') c1+=a[r++]=='1';
			r--;
			int c0=r-l+1-c1;
			int lb=l,rb=r;
			while(lb<=r&&tb[lb]=='1'&&tb[lb-1]=='1') lb++;
			while(rb>=l&&tb[rb]=='1'&&tb[rb+1]=='1') rb--;
//			printf("%d %d %d %d\n",l,r,lb,rb);
//			printf("%c %c\n",tb[rb],tb[rb+1]);
			for(int i=lb;i<=rb;i++)
			{
				if(b[i]=='1')
				{
					if(c1>0) ans++,c1--;
					else c0--;
				}
				else
				{
					if(c0>0) ans++,c0--;
					else c1--;
				}
			}
			tmp[++m]=(node){l,r,c1,c0};
			l=r;
		}
	}
//	printf("%d\n",ans);
	for(int l=1;l<=n;l++)
	{
		if(tb[l]=='1')
		{
			int c1=0;
			int r=l;
			while(r<=n&&tb[r]=='1') c1+=b[r++]=='1';
			r--;
			int c0=r-l+1-c1;
			int lb=l,rb=r;
			while(lb<=r&&ta[lb]=='1'&&ta[lb-1]=='1') lb++;
			while(rb>=l&&ta[rb]=='1'&&ta[rb+1]=='1') rb--;
			bool fl=lb==l&&rb==r;
			for(int i=lb;i<=rb&&fl;i++) fl&=ta[i]=='1';
			if(fl)
			{
				l=r;
				continue;
			}
			for(int i=lb;i<=rb;i++)
			{
				if(a[i]=='1')
				{
					if(c1>0) ans++,c1--;
					else c0--;
				}
				else
				{
					if(c0>0) ans++,c0--;
					else c1--;
				}
			}
			tmp[++m]=(node){l,r,c1,c0};
			l=r;
		}
	}
	sort(tmp+1,tmp+m+1,[&](node x,node y){
		if(x.l==y.l) return x.r>y.r;
		return x.l<y.l;
	});
	for(int i=1;i<=m;)
	{
		int j=i+1;
		while(j<=m&&tmp[j].r<=tmp[i].r) j++;
		if(j>m||tmp[j].l>tmp[i].r) i=j;
		else
		{
			int &i1=tmp[i].c1,&i0=tmp[i].c0;
			int &j1=tmp[j].c1,&j0=tmp[j].c0;
			if(i1<=j1) ans+=i1,j1-=i1;
			else ans+=j1,j0-=i1-j1,j1=0;
			if(i0<=j0) ans+=i0,j0-=i0;
			else ans+=j0,j1-=i0-j0,j0=0;
			i=j;
		}
	}
	printf("%d\n",ans);
}

int main()
{
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	int T;
	read(T);
	while(T-->0) slove();
	return 0;
}
