#include<bits/stdc++.h>
#define ll long long
#define ls u<<1
#define rs u<<1|1
#define up(i,a,b) for(int i=a;i<=b;i++)
#define dn(i,a,b) for(int i=a;i>=b;i--)
using namespace std;
const int N=2e5+10;
int n,_,ans,cnt[N][10],to[N],to2[N],vis[N],tot;
struct node
{
	int l,r,id,k;
}a[N];
string s[10],t[10];
int main()
{
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	cin>>_;
	while(_--)
	{
		cin>>n;
		ans=0;
		up(i,1,2)cin>>s[i],s[i]=' '+s[i];
		up(i,1,2)cin>>t[i],t[i]=' '+t[i];
		int ok=0;
		up(i,1,n+1)
		{
			if(t[1][i]=='1')
			{
				if(!ok)ok=1,tot++,a[tot].l=i,a[tot].id=1,a[tot].k=tot;
				to[i]=tot;
				cnt[tot][s[1][i]-'0']++;
			}
			else if(ok)ok=0,a[tot].r=i-1;
		}
		ok=0;
		up(i,1,n+1)
		{
			if(t[2][i]=='1')
			{
				if(!ok)ok=1,tot++,a[tot].l=i,a[tot].id=2,a[tot].k=tot;
				to2[i]=tot;
				cnt[tot][s[2][i]-'0']++;
			}
			else if(ok)ok=0,a[tot].r=i-1;
		}
		sort(a+1,a+tot+1,[](node a,node b){return a.l==b.l?a.r>b.r:a.l<b.l;});
		up(i,1,tot)
		{
			int u=a[i].id,v=(a[i].id==1?2:1);
			up(j,a[i].l,a[i].r)
			{
				if(cnt[a[i].k][s[v][j]-'0'])
				{
					s[u][j]=s[v][j];
					cnt[a[i].k][s[u][j]-'0']--;
				}
				else s[u][j]=(s[v][j]=='0'?'1':'0');
			}
		}
		up(i,1,tot)cnt[i][0]=cnt[i][1]=0,vis[i]=0;
		tot=0;
		up(i,1,n)if(s[1][i]==s[2][i])ans++;
		cout<<ans<<"\n";
	}
	
	return 0;
}
