#include<bits/stdc++.h>
#define de(x) cout<<#x<<": "<<x<<endl;
#define rep(i,a,b) for(int i(a);i<=(b);++i)
#define REP(i,a,b) for(int i(a);i>=(b);--i)
using namespace std;
const int N=2e5 +7;
int n,p[N],p2[N],f0[N][2],f1[N][2],pt[N],pt0[N],lt[N],c1,c2;
string A,B,S,t;
inline int can(int i,int j)
{
return f0[i][0]+f0[i][1]>pt0[i] && f1[j][0]+f1[j][1]>pt[j];
}
signed main()
{
freopen("edit.in","r",stdin);
freopen("edit.out","w",stdout);
int T; cin>>T;
while(T--)
{
cin>>n>>A>>B>>S>>t,c1=c2=0;
A=' '+A,B=' '+B,S=' '+S,t=' '+t;
rep(i,1,n)
{
int j=i; ++c1;
if(S[i]=='1') { while(j<=n && S[j]=='1') ++j; --j; }
rep(k,i,j) p[k]=c1,f0[c1][A[k]-'0']++;
i=j;
}
rep(i,1,n)
{
int j=i; ++c2;
if(t[i]=='1') { while(j<=n && t[j]=='1') ++j; --j; }
rep(k,i,j) p2[k]=c2,f1[c2][B[k]-'0']++;
lt[c2]=j,i=j;
}
int ret=0;
rep(i,1,n)
{
int j=i;
if(S[i]=='1') { while(j<=n && S[j]=='1') ++j; --j; }
rep(k,p2[i],p2[j])
{
while(f0[p[i]][0] && f1[k][0] && can(p[i],k)) ++ret,--f0[p[i]][0],--f1[k][0];
while(f0[p[i]][1] && f1[k][1] && can(p[i],k)) ++ret,--f0[p[i]][1],--f1[k][1];
if(lt[k]<=j) pt0[p[i]]+=f1[k][0]+f1[k][1]-pt[k];
else pt[k]+=f0[p[i]][0]+f0[p[i]][1]-pt0[p[i]];
}
i=j;
}
cout<<ret<<endl;
rep(i,0,n+1) rep(j,0,1) f0[i][j]=f1[i][j]=0;
rep(i,0,n+1) p[i]=p2[i]=pt[i]=pt0[i]=lt[i]=0;
}
return 0;
}