#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#define N 100010
using namespace std;
int t,n;
string s1,s2,t1,t2;
int a1[N],a2[N];
int b1[N],b2[N];
int ans,ans1,ans2;
int main()
{
freopen("edit.in","r",stdin);
freopen("edit.out","w",stdout);
cin>>t;
while(t--)
{
ans=ans1=ans2=0;
bool flag=1,flag2=1;
cin>>n;
cin>>s1>>s2>>t1>>t2;
t1=' '+t1,t2=' '+t2;
for(int i=1;i<=n;i++)
{
if(i<n&&s1[i]!=s1[i-1]) flag=0;
if(t1[i]!=t2[i]) flag2=0;
a1[i]=a1[i-1]+(s1[i-1]=='1'),a2[i]=a2[i-1]+(s1[i-1]=='0');
b1[i]=b1[i-1]+(s2[i-1]=='1'),b2[i]=b2[i-1]+(s2[i-1]=='0');
}
int last=0;
if(flag)
for(int i=1;i<=n;i++)
ans1+=(s2[i-1]==s1[i-1]);
if(flag2)
for(int i=1;i<=n;i++) if(t1[i]=='0') ans2+=(s2[i-1]==s1[i-1])+min(b1[i-1]-b1[last],a1[i-1]-a1[last])+min(b2[i-1]-b2[last],a2[i-1]-a2[last]),last=i;
if(t1[n]!='0') ans2+=min(b1[n]-b1[last],a1[n]-a1[last])+min(b2[n]-b2[last],a2[n]-a2[last]);
last=0;
int k1_1=0,k1_0=0,k2_1=0,k2_0=0;
for(int i=1;i<=n;i++)
{
int x=a1[i]-a1[last]+k1_1,y=b1[i]-b1[last]+k2_1;
int xx=a2[i]-a2[last]+k1_0,yy=b2[i]-b2[last]+k2_0;
if(t1[i]=='0'&&t2[i]=='1')
{
ans+=min(x,y)+min(xx,yy);
k2_1=max(y-x,0),k2_0=max(yy-xx,0);
k1_1=k1_0=0,last=i;
}
else if(t1[i]=='1'&&t2[i]=='0')
{
ans+=min(x,y)+min(xx,yy);
k1_1=max(x-y,0),k1_0=max(xx-yy,0);
k2_1=k2_0=0,last=i;
}
else if(t1[i]=='0'&&t2[i]=='0')
{
if(s1[i-1]==s2[i-1]) ans++;
ans+=min(a1[i-1]-a1[last]+k1_1,b1[i-1]-b1[last]+k2_1)+min(a2[i-1]-a2[last]+k1_0,b2[i-1]-b2[last]+k2_0);
k2_1=k2_0=k1_1=k1_0=0,last=i;
}
}
if(n!=last) ans+=min(a1[n]-a1[last]+k1_1,b1[n]-b1[last]+k2_1)+min(a2[n]-a2[last]+k1_0,b2[n]-b2[last]+k2_0);
if(flag) cout<<ans1<<endl;
else if(flag2) cout<<ans2<<endl;
else cout<<ans<<endl;
}
return 0;
}