#include<bits/stdc++.h>
#define M 1000001
using namespace std;
inline int read()
{
	int k=0,f=0;char c=getchar();
	for(;!isdigit(c);c=getchar()) f|=c=='-';
	for(;isdigit(c);c=getchar()) k=(k<<1)+(k<<3)+(c^48);
	return f?-k:k;
}
inline void write(int x)
{
	if(x<0) putchar('-'),x=-x;
	int stk[35],top=0;
	stk[top++]=x%10,x/=10;
	while(x) stk[top++]=x%10,x/=10;
	while(top) putchar(stk[--top]+48);
	puts("");
}
int T,n,s1[M],s2[M],ans;
char x;
queue<int> t1,t2;
struct node
{
	int head,tail;
};
inline void get_in(){
	int last=0;
	while(!t1.empty()) t1.pop();
	while(!t2.empty()) t2.pop();
	for(int i=1;i<=n;i++) s1[i]=s2[i]=0;
	for(int i=1;i<=n;i++)
	{
		cin>>x;
		s1[i]=s1[i-1]+(x-'0');
	}
	for(int i=1;i<=n;i++)
	{
		cin>>x;
		s2[i]=s2[i-1]+(x-'0');
	}
	for(int i=1;i<=n;i++)
	{
		cin>>x;
		if(x=='0')
		{
			if(i-1!=last) t1.push(i-1);
			t1.push(i),last=i;
		}
	}
	if(x=='1') t1.push(n);
	last=0;
	for(int i=1;i<=n;i++)
	{
		cin>>x;
		if(x=='0')
		{
			if(i-1!=last) t2.push(i-1);
			t2.push(i),last=i;
		}
	}
	if(x=='1') t2.push(n);
	return;
}
int main()
{
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	T=read();
	while(T--)
	{
		n=read(),get_in(),t1.push(n+1),t2.push(n+1),ans=0;
		int cnt0=0,cnt1=0,cnt2=0,cnt3=0;
		node a,b;
		a.head=b.head=1,a.tail=t1.front(),t1.pop(),b.tail=t2.front(),t2.pop();
		cnt1=s1[a.tail]-s1[a.head-1],cnt0=a.tail-cnt1-a.head+1;
		cnt3=s2[b.tail]-s2[b.head-1],cnt2=b.tail-cnt3-b.head+1;
		while(a.head<=n&&b.head<=n)
		{
			if(a.tail==b.tail)
			{
				ans+=min(cnt0,cnt2)+min(cnt1,cnt3);
				a.head=a.tail+1,b.head=b.tail+1,a.tail=t1.front(),b.tail=t2.front(),t1.pop(),t2.pop();
				cnt1=s1[a.tail]-s1[a.head-1],cnt0=a.tail-cnt1-a.head+1;
				cnt3=s2[b.tail]-s2[b.head-1],cnt2=b.tail-cnt3-b.head+1;
			}
			else if(a.tail<b.tail)
			{
				int match0=min(cnt0,cnt2),match1=min(cnt1,cnt3);
				ans+=match0+match1;
				if(match0==cnt2) cnt3=cnt3+cnt2-cnt0-cnt1,cnt2=0;
				else if(match1==cnt3) cnt2=cnt2+cnt3-cnt0-cnt1,cnt3=0;
				else cnt2-=match0,cnt3-=match1;
				a.head=a.tail+1,a.tail=t1.front(),t1.pop();
				cnt1=s1[a.tail]-s1[a.head-1],cnt0=a.tail-cnt1-a.head+1;
			}
			else
			{
				int match0=min(cnt0,cnt2),match1=min(cnt1,cnt3);
				ans+=match0+match1;
				if(match0==cnt0) cnt1=cnt0+cnt1-cnt2-cnt3,cnt0=0;
				else if(match1==cnt1) cnt0=cnt0+cnt1-cnt2-cnt3,cnt1=0;
				else cnt0-=match0,cnt1-=match1;
				b.head=b.tail+1,b.tail=t2.front(),t2.pop();
				cnt3=s2[b.tail]-s2[b.head-1],cnt2=b.tail-cnt3-b.head+1;
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}
