//T1 edit designed by S_Kuroko
#include<bits/stdc++.h>
//#define int long long
using namespace std;
const int N=1e5+50;

int a[N],b[N];
int cz1[N],cz2[N];
struct node{
	int l,r;
	int numa1,numb1;
}liantong[N];
int tot=0;

int fa1[N],fa2[N];
int find1(int x)
{
	if(x==fa1[x]) return x;
	return fa1[x]=find1(fa1[x]);
}
int find2(int x)
{
	if(x==fa2[x]) return x;
	return fa2[x]=find2(fa2[x]);
}
int num10[N],num11[N],num20[N],num21[N];
void merge1(int x,int y)
{
	int f1=find1(x),f2=find1(y);
	fa1[f2]=f1;
}
void merge2(int x,int y)
{
	int f1=find2(x),f2=find2(y);
	fa2[f2]=f1;
}

int main()
{
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	int T;
	cin>>T;
	while(T--)
	{
		memset(a,0,sizeof(a));
		memset(b,0,sizeof(b));
		memset(cz1,0,sizeof(cz1));
		memset(cz2,0,sizeof(cz2));
		memset(fa1,0,sizeof(fa1));
		memset(fa2,0,sizeof(fa2));
		memset(num10,0,sizeof(num10));
		memset(num11,0,sizeof(num11));
		memset(num20,0,sizeof(num20));
		memset(num21,0,sizeof(num21));
		for(int i=0;i<100000;i++)
		{
			liantong[i].l=0;
			liantong[i].r=0;
			liantong[i].numa1=0;
			liantong[i].numb1=0;
		}
		tot=0;
		int n;
		cin>>n;
		for(int i=1;i<=n;i++)
		{
			fa1[i]=i;
		}
		for(int i=1;i<=n;i++)
		{
			fa2[i]=i;
		}
		string s11,s22,t11,t22;
		cin>>s11>>s22>>t11>>t22;
		bool flagA=1,flagB=0;
		if(t11==t22) flagB=1;
		else flagB=0;
		for(int i=1;i<=n;i++)
		{
			a[i]=s11[i-1]-'0';
			if((i>1)&&a[i]!=a[i-1]) flagA=0;
			b[i]=s22[i-1]-'0';
			cz1[i]=t11[i-1]-'0';
			cz2[i]=t22[i-1]-'0';
		}
		if(flagA)
		{
			int ans=0;
			for(int i=1;i<=n;i++)
				if(b[i]==a[i])	ans++;
			cout<<ans<<endl;
			continue;
		}
		if(flagB)
		{
			for(int i=1;i<=n;i++)
			{
				if(cz1[i]==1&&cz1[i-1]!=1)
					liantong[++tot].l=i;
				if(cz1[i]==0&&cz1[i-1]!=0)
					liantong[tot].r=i-1;
			}
			if(liantong[tot].r==0) liantong[tot].r=n;
			int ans=0;
			for(int i=1;i<=tot;i++)
			{
				for(int j=liantong[i].l;j<=liantong[i].r;j++)
				{
					if(a[j]==1) liantong[i].numa1++;
					if(b[j]==1) liantong[i].numb1++;
				}
			}
			for(int i=1;i<=tot;i++)
			{
				int dif=abs(liantong[i].numa1-liantong[i].numb1);
				ans+=(liantong[i].r-liantong[i].l+1)-dif;
			}
			for(int i=1;i<=n;i++)
			{
				if(cz1[i]==0)
				{
					ans+=(a[i]==b[i]);
				}
			}
			cout<<ans<<endl;
			continue;
		}
		for(int i=1;i<=n;i++)//去除单个游离可操作的字符 
		{
			if(cz1[i]==1&&(i==1||cz1[i-1]==0)&&(i==n||cz1[i+1]==0))
			{
				cz1[i]=0;
			}
			if(cz2[i]==1&&(i==1||cz2[i-1]==0)&&(i==n||cz2[i+1]==0))
			{
				cz2[i]=0;
			}
		}
		for(int i=1;i<=n;i++)
		{
			if(cz1[i]==1&&cz1[i-1]==1)
			{
				merge1(i-1,i);
				if(a[i]==1) num11[fa1[i]]++;
				else num10[fa1[i]]++;
			}
			if(cz2[i]==1&&cz2[i-1]==1)
			{
				merge2(i-1,i);
				if(b[i]==1) num21[fa2[i]]++;
				else num20[fa2[i]]++;
			}
		}
		int ans=0;
		for(int i=1;i<=n;i++)
		{
			if((cz1[i]==1&&cz2[i]==1)&&(cz1[i-1]==0||cz2[i-1]==0))
				liantong[++tot].l=i;
			if((cz1[i]==1&&cz2[i]==1)&&(cz1[i+1]==0||cz2[i+1]==0))
				liantong[tot].r=i;
		}
		if(liantong[tot].r==0) liantong[tot].r=n;
		for(int i=1;i<=tot;i++)
		{
			for(int j=liantong[i].l;j<=liantong[i].r;j++)
			{
				if(a[j]==1) liantong[i].numa1++;
				if(b[j]==1) liantong[i].numb1++;
			}
		}
		int tot2=0;
		for(int i=1;i<=n;i++)
		{
			if(i<=liantong[tot2+1].r&&i>=liantong[tot2+1].l) tot2++;
			if(cz1[i]==0)
			{
				if(cz2[i]==0)
				{
					if(a[i]==b[i])
					{
						ans++;
					}
				}
				else if(cz2[i]==1)
				{
					int f2=fa2[i];
					if(a[i]==0)
					{
						if(b[i]==0)
						{
							ans++;
							num20[f2]--;
						}
						else
						{
							if(num20[f2])
							{
								ans++;
								num20[f2]--;
							}
							else
							{
								num21[f2]--;
								liantong[tot2].numb1--;
							}
						}
					}
					else if(a[i]==1)
					{
						if(b[i]==1)
						{
							ans++;
							num21[f2]--;
							liantong[tot2].numb1--;
						}
						else
						{
							if(num21[f2])
							{
								ans++;
								num21[f2]--;
								liantong[tot2].numb1--;
							}
							else
							{
								num20[f2]--;
							}
						}
					}
				}
			}
			else if(cz1[i]==1)
			{
				if(cz2[i]==0)
				{
					int f1=fa1[i];
					if(b[i]==0)
					{
						if(a[i]==0)
						{
							ans++;
							num10[f1]--;
						}
						else if(a[i]==1)
						{
							if(num10[f1])
							{
								ans++;
								num10[f1]--;
							}
							else
							{
								num11[f1]--;
								liantong[tot2].numa1--;
							}
						}
					}
					else if(b[i]==1)
					{
						if(a[i]==1)
						{
							ans++;
							num11[f1]--;
							liantong[tot2].numa1--;
						}
						else if(a[i]==0)
						{
							if(num11[f1])
							{
								ans++;
								num11[f1]--;
								liantong[tot2].numa1--;
							}
							else
							{
								num10[f1]--;
							}
						}
					}
				}
//				else if(cz2[i]==1)//a,b都是可操作的 
//				{
//					liantong[++tot].l
//				}
			}
		}
		for(int i=1;i<=tot;i++)
		{
			int dif=abs(liantong[i].numa1-liantong[i].numb1);
			ans+=(liantong[i].r-liantong[i].l+1)-dif;
		}
		cout<<ans<<endl;
	}
	return 0;
}
//T1 finished from 8:40 to 
