#include<iostream>
#include<string>
using namespace std;
#define N 100010
int t,n,cnta0[N],cnta1[N],cntb0[N],cntb1[N];
string a,visa,b,visb;
int main()
{
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>t;
	while(t--)
	{
		cin>>n;
		for(int i=1;i<=n;i++)
		{
			cnta0[i]=0;
			cnta1[i]=0;
			cntb0[i]=0;
			cntb1[i]=0;
		}
		cin>>a;
		a=" "+a;
		cin>>b;
		b=" "+b;
		cin>>visa;
		visa=" "+visa;
		cin>>visb;
		visb=" "+visb;
		int pre0=0,pre1=0;
		for(int i=n;i>=1;i--)
		{
			if(a[i]=='0')
			 pre0++;
			else
			 pre1++;
			if(i==1||visa[i]=='0'||visa[i-1]=='0')
			{
				cnta0[i]=pre0;
				cnta1[i]=pre1;
				pre0=0;
				pre1=0;
			}
		}
		for(int i=n;i>=1;i--)
		{
			if(b[i]=='0')
			 pre0++;
			else
			 pre1++;
			if(i==1||visb[i]=='0'||visb[i-1]=='0')
			{
				cntb0[i]=pre0;
				cntb1[i]=pre1;
				pre0=0;
				pre1=0;
			}
		}
		int ca0=0,ca1=0,cb0=0,cb1=0,ans=0;
		for(int i=1;i<=n;i++)
		{
			ca0+=cnta0[i];
			ca1+=cnta1[i];
			cb0+=cntb0[i];
			cb1+=cntb1[i];
			if(ca0&&cb0)
			{
				ans++;
				ca0--;
				cb0--;
			}
			else if(ca1&&cb1)
			{
				ans++;
				ca1--;
				cb1--;
			}
			else if(ca0&&cb1)
			{
				ca0--;
				cb1--;
			}
			else if(ca1&&cb0)
			{
				ca1--;
				cb0--;
			}
		}
		cout<<ans<<"\n";
	}
}
