#include<bits/stdc++.h>
#include<cstdio>
using namespace std;
const int MAXN=1e5+10;
int T,n;
char a[MAXN],b[MAXN];
int t1[MAXN],t2[MAXN];
bool flagA,flagB,flagC;
int num1,num2;
void work_A()
{
	int ans=0;
	for(int i=1;i<=n;i++)
	{
		if(b[i]==a[i]) ans++;
	}
	printf("%d\n",ans);
	return ;
}
void work_B()
{
	int ans=0;
	int pos1=0,pos2=0;
	int num1=0,num2=0;
	for(int i=1;i<=n;i++)
	{
		if(t1[i]==0)
		{
			pos2=i;
		}else{
			num1+=(a[i]=='0');
			num2+=(b[i]=='0');
		}
		if(pos2!=0 || i==n)
		{
			if(i==n && pos2==0) pos2=n+1; 
			int len=pos2-pos1-1;
			if(a[pos2]==b[pos2] && pos2!=n+1) ans++;
			ans+=(len-num1<len-num2?len-num1:len-num2)+(num1<num2?num1:num2);
			pos1=pos2;
			pos2=0;
			num1=num2=0;
		}
	}
	printf("%d\n",ans);
}
signed main()
{
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	scanf("%d",&T);
	while(T--)
	{
		num1=num2=0;
		flagA=flagB=flagC=true;
		scanf("%d",&n);
		for(int i=1;i<=n;i++)
		{
			cin >> a[i]; 
		}
		for(int i=1;i<=n;i++)
		{
			cin >> b[i];
		}
		for(int i=1;i<=n;i++)
		{
			char c;
			cin >> c;
			t1[i]=c-'0';
			if(a[i]!=a[i-1] && i!=1) flagA=false;
		}
		for(int i=1;i<=n;i++)
		{
			char c;
			cin >> c;
			t2[i]=c-'0';
			if(t2[i]!=t1[i]) flagB=false;
		}
		if(flagA) work_A();
		if(flagB) work_B();
	}
	return 0;
} 
