#include<bits/stdc++.h>
using namespace std;
const int N=1e5+13;
int t,n;
int s1[N],s2[N];
int t1[N],t2[N];
bool fa=1,fb=1;
char skr;
int ans;
void A()
{
	int x=s1[1];
	for(int i=1;i<=n;i++)
		if(x==s2[i]) ans++;	
}
void B()
{
	int p1[N],p2[N];
	for(int i=1;i<=n;i++)
		p1[i]=p1[i-1]+s1[i],p2[i]=p2[i-1]+s2[i];
	queue<int> q;
	for(int i=1;i<=n;i++)
		if(t1[i]==0) q.push(i); 
	q.push(n+1);
	int st=0,en=q.front();
	q.pop();
	while(1)
	{
		ans+=(en-st)-abs(p1[en-1]-p2[en-1]);
		if(s1[en]==s2[en]&&en!=n+1) ans++;
		st=en+1;en=q.front();
		if(st>n) break; 
		q.pop();
	}
}
int main()
{
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	cin>>t;
	while(t--)
	{
		
		scanf("%d",&n);
		for(int i=1;i<=n;i++) 
		{
			cin>>skr;
			if(skr=='1') s1[i]=1;
			else s1[i]=0;		
			if(i>=2&&s1[i]!=s1[i-1]) fa=0;	
		}
		for(int i=1;i<=n;i++)
		{
			cin>>skr;
			if(skr=='1') s2[i]=1;
			else s2[i]=0;		
		}
		for(int i=1;i<=n;i++) 
		{
			cin>>skr;
			if(skr=='1') t1[i]=1;
			else t1[i]=0;	
		}
		for(int i=1;i<=n;i++)
		{
			cin>>skr;
			if(skr=='1') t2[i]=1;
			else t2[i]=0;	
		}
		if(fa)
		{
			A(); 
		} 
		else
		{
			for(int i=1;i<=n;i++)
				if(t1[i]!=t2[i]) fb=0;
			if(fb)
			{
				B();
			}
		}
		if(ans==0) cout<<n<<endl;
		printf("%d\n",ans);
	}
	return 0;
} 
//40pts 
