#include<bits/stdc++.h>
using namespace std;
#define int long long
inline int read()
{
int x=0,f=1;
char c=getchar();
while(c<'0'||c>'9')
{
if(c=='-')
f=-1;
c=getchar();
}
while(c>='0'&&c<='9')
x=(x<<3)+(x<<1)+(c^48),c=getchar();
return x*f;
}
void write(int x)
{
if(x<0)
putchar('-'),x=-x;
if(x>9)
write(x/10);
putchar('0'+x%10);
}
const int N=1e5+5;
char s[N],t[N],u[N],v[N];
int sc[2],tc[2];
void solve()
{
int n=read();
scanf("%s",s+1);
scanf("%s",t+1);
scanf("%s",u+1);
scanf("%s",v+1);
memset(sc,0,sizeof(sc));
memset(tc,0,sizeof(tc));
int ans=0;
int i=1,j=1;
if(u[i]=='1')
{
sc[s[i]-'0']++;
while(i<n&&u[i+1]=='1')
i++,sc[s[i]-'0']++;
}
if(v[j]=='1')
{
tc[t[j]-'0']++;
while(j<n&&v[j+1]=='1')
j++,tc[t[j]-'0']++;
}
for(;i<=n||j<=n;)
{
if(i<j)
{
if(u[i]=='0')
{
if(tc[s[i]-'0'])
tc[s[i]-'0']--,ans++;
else
tc[1-(s[i]-'0')]--;
i++;
memset(sc,0,sizeof(sc));
if(u[i]=='1')
{
sc[s[i]-'0']++;
while(i<n&&u[i+1]=='1')
i++,sc[s[i]-'0']++;
}
}
else
{
for(int k=0;k<2;k++)
{
int g=min(sc[k],tc[k]);
ans+=g;
sc[k]-=g,tc[k]-=g;
if(sc[k])
tc[1-k]-=sc[k];
}
memset(sc,0,sizeof(sc));
i++;
if(u[i]=='1')
{
sc[s[i]-'0']++;
while(i<n&&u[i+1]=='1')
i++,sc[s[i]-'0']++;
}
}
}
else if(i>j)
{
if(v[j]=='0')
{
if(sc[t[j]-'0'])
sc[t[j]-'0']--,ans++;
else
sc[1-(t[j]-'0')]--;
j++;
memset(tc,0,sizeof(tc));
if(v[j]=='1')
{
tc[t[j]-'0']++;
while(j<n&&v[j+1]=='1')
j++,tc[t[j]-'0']++;
}
}
else
{
for(int k=0;k<2;k++)
{
int g=min(sc[k],tc[k]);
ans+=g;
sc[k]-=g,tc[k]-=g;
if(tc[k])
sc[1-k]-=tc[k];
}
j++;
memset(tc,0,sizeof(tc));
if(v[j]=='1')
{
tc[t[j]-'0']++;
while(j<n&&v[j+1]=='1')
j++,tc[t[j]-'0']++;
}
}
}
else
{
if(u[i]=='0')
{
memset(sc,0,sizeof(sc));
sc[s[i]-'0']++;
}
if(v[j]=='0')
{
memset(tc,0,sizeof(tc));
tc[t[j]-'0']++;
}
for(int k=0;k<2;k++)
{
int g=min(sc[k],tc[k]);
ans+=g;
sc[k]-=g,tc[k]-=g;
}
memset(sc,0,sizeof(sc));
memset(tc,0,sizeof(tc));
i++;
if(u[i]=='1')
{
sc[s[i]-'0']++;
while(i<n&&u[i+1]=='1')
i++,sc[s[i]-'0']++;
}
j++;
if(v[j]=='1')
{
tc[t[j]-'0']++;
while(j<n&&v[j+1]=='1')
j++,tc[t[j]-'0']++;
}
}
}
write(ans);
puts("");
}
signed main()
{
freopen("edit.in","r",stdin);
freopen("edit.out","w",stdout);
int dd=read();
while(dd--)
solve();
return 0;
}