#include<bits/stdc++.h>
using namespace std;
int t,n,sa[100010],sb[100010],ta[100010],tb[100010],num1[100010],num2[100010],num3[100010],num4[100010];
int main(){
freopen("edit.in","r",stdin);
freopen("edit.out","w",stdout);
cin>>t;
for(int e=1;e<=t;e++){
cin>>n;
memset(num1,0,sizeof(num1));
memset(num2,0,sizeof(num2));
memset(num3,0,sizeof(num3));
memset(num4,0,sizeof(num4));
bool flag=true,fla=true;
int x=0,y=0,t1,t2;
for(int i=1;i<=n;i++){
cin>>sa[i];
if(sa[i]==0){
num1[i]=num1[i-1]+1;
num2[i]=num2[i-1];
}
else{
num1[i]=num1[i-1];
num2[i]=num2[i-1]+1;
}
if(sa[i]!=sa[i-1]&&i>=2)flag=false;
}
for(int i=1;i<=n;i++){
cin>>sb[i];
if(sb[i]==0){
num3[i]=num3[i-1]+1;
num4[i]=num4[i-1];
}
else{
num3[i]=num3[i-1];
num4[i]=num4[i-1]+1;
}
}
for(int i=1;i<=n;i++)
cin>>ta[i];
for(int i=1;i<=n;i++)
cin>>tb[i];
if(flag==true){
cout<<min(num1[n],num3[n])+min(num2[n],num4[n])<<endl;
continue;
}
for(int i=1;i<=n;i++){
if(ta[i]!=tb[i])fla=false;
if(ta[i]==0){
x++;
t1=i;
}
if(tb[i]==0){
y++;
t2=i;
}
}
if(fla==true){
int ans=0,l=0;
for(int i=1;i<=n;i++){
if(ta[i]==0){
if(sa[i]==sb[i])ans++;
}
if(ta[i]==1){
if(ta[i-1]==0)l=i;
if(ta[i+1]==0){
ans+=min(num1[i]-num1[l-1],num3[i-1]-num3[l-1]);
ans+=min(num2[i-1]-num2[l-1],num4[i-1]-num4[l-1]);
}
}
}
cout<<ans<<endl;
continue;
}
if(x==1&&y==1){
int ans=0;
if(t1<t2){
ans+=min(num1[t1-1],num3[t1-1]);
ans+=min(num2[t1-1],num4[t1-1]);
ans+=min(num1[t2-1]-num1[t1],num3[t2-1]-num3[t1]);
ans+=min(num2[t2-1]-num2[t1],num4[t2-1]-num4[t1]);
ans+=min(num1[n]-num1[t2],num3[n]-num3[t2]);
ans+=min(num2[b]-num2[t2],num4[n]-num4[t2]);
if(sa[t1]==sb[t1])ans++;
if(sa[t2]==sb[t2])ans++;
}
if(t1==t2){
ans+=min(num1[t1-1],num3[t1-1]);
ans+=min(num2[t1-1],num4[t1-1]);
ans+=min(num1[n]-num1[t2],num3[n]-num3[t2]);
ans+=min(num2[b]-num2[t2],num4[n]-num4[t2]);
if(sa[t2]==sb[t2])ans++;
}
if(t1>t2){
ans+=min(num1[t2-1],num3[t2-1]);
ans+=min(num2[t2-1],num4[t2-1]);
ans+=min(num1[t2-1]-num1[t1],num3[t2-1]-num3[t1]);
ans+=min(num2[t2-1]-num2[t1],num4[t2-1]-num4[t1]);
ans+=min(num1[n]-num1[t2],num3[n]-num3[t2]);
ans+=min(num2[b]-num2[t2],num4[n]-num4[t2]);
if(sa[t1]==sb[t1])ans++;
if(sa[t2]==sb[t2])ans++;
}
cout<<ans;
}
}
return 0;
}