#include<bits/stdc++.h>
using namespace std;
const int Maxn=1e5+10;
string sx,sy,bx,by;
int fax[Maxn],fay[Maxn],cx[Maxn][3],cy[Maxn][3];
int Findx(int x)
{
	if(fax[x]==x)return x;
	else return fax[x]=Findx(fax[x]);
}
int Findy(int x)
{
	if(fay[x]==x)return x;
	else return fay[x]=Findy(fay[x]);
}
void Mergex(int x,int y)
{
	fax[Findx(x)]=Findx(y);
}
void Mergey(int x,int y)
{
	fay[Findy(x)]=Findy(y);
}
signed main()
{
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int T,n;
	cin>>T;
	while(T--)
	{
		memset(cx,0,sizeof(cx));
		memset(cy,0,sizeof(cy));
		int cntx[3],cnty[3];
		cntx[0]=cntx[1]=cnty[0]=cnty[1]=0;
		int ans=0;
		cin>>n>>sx>>sy>>bx>>by;
		for(int i=0;i<n;i++)fax[i]=i,fay[i]=i;
		int lst=0;
		for(int i=1;i<n;i++)
		{
			if(bx[i]=='1'&&bx[i-1]=='1')Mergex(i-1,i);
			if(by[i]=='1'&&by[i-1]=='1')Mergey(i-1,i);
		}
		for(int i=n-1;i>=0;i--)fax[i]=Findx(i),fay[i]=Findy(i);
		cx[0][sx[0]-'0']=1,cy[0][sy[0]-'0']=1;
		for(int i=1;i<n;i++)
		{
			cx[i][sx[i]-'0']=1;
			if(bx[i]=='1'&&bx[i-1]=='1')
			{
				cx[i][0]+=cx[i-1][0];
				cx[i][1]+=cx[i-1][1];
			}
			cy[i][sy[i]-'0']=1;
			if(by[i]=='1'&&by[i-1]=='1')
			{
				cy[i][0]+=cy[i-1][0];
				cy[i][1]+=cy[i-1][1];
			}
		}
		for(int i=0;i<n;i++)
		{
			int fx=Findx(i),fy=Findy(i);
			if(cx[fx][0]&&cy[fy][0])
			{
				cx[fx][0]--;
				cy[fy][0]--;
				ans++;
				continue;
			}
			if(cx[fx][1]&&cy[fy][1])
			{
				cx[fx][1]--;
				cy[fy][1]--;
				ans++;
				continue;
			}
			if(cx[fx][0]&&cy[fy][1])
			{
				cx[fx][0]--;
				cy[fy][1]--;
				continue;
			}
			if(cx[fx][1]&&cy[fy][0])
			{
				cx[fx][1]--;
				cy[fy][0]--;
				continue;
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}
//thank goodness
