太痛苦了,交了 6 发都 WA 第二个点……
有带佬帮忙看看为啥 WA 吗……
#include<bits/stdc++.h>
using namespace std;
#define debug(x) cerr << "Debug in line " << __LINE__ << " : " << #x << " = " << x << "\n" ;
#define rep(i,a,b) for (int i=(a); i<(b); i++)
#define per(i,a,b) for (int i=(b)-1; i>=(a); i--)
#define pb push_back
#define mp std::make_pair
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define fileio(s) freopen(s".in", "r", stdin);freopen(s".out","w",stdout)
typedef unsigned long long ull;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef long long ll;
typedef double db;
mt19937 mt_rng(random_device{}());
int rnd(int x) {return mt_rng() % x;}
const ll mod=1000000007;
ll powmod(ll b, ll e, ll md=mod) {ll a=1; assert(e>=0); for (;e;e>>=1, b=b*b%md) if(e&1) {a=a*b%md;} return a;}
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
// head
inline ll read()
{
ll x=0;
int f=1;char ch=getchar();
while (ch<'0'||ch>'9'){if (ch=='-') f=-1;ch=getchar();}
while (ch>='0'&&ch<='9'){x=x*10+ch-48;ch=getchar();}
return x*f;
}
const int N=201000;
int n;
ll a[3][N], cyc[3][N];
ll calc(ll t, ll x) {
if (t<x) return x-t+1;
return 1;
}
void go(ll &t, ll x) { t += calc(t,x); }
void solve() {
memset(cyc, 0, sizeof(cyc));
scanf("%d",&n);
rep(k,1,3) rep(i,1,n+1) a[k][i]=read();
cyc[1][n]=calc(a[1][n],a[2][n]);
per(i,1,n) cyc[1][i]=cyc[1][i+1]+calc(a[1][i],a[1][i+1])+calc(a[2][i+1],a[2][i]);
cyc[2][n]=calc(a[2][n],a[1][n]);
per(i,1,n) cyc[2][i]=cyc[2][i+1]+calc(a[2][i],a[2][i+1])+calc(a[1][i+1],a[1][i]);
ll ans=0;
ll t=0;
rep(i,1,n+1) {
if (i!=1) go(t,a[1][i]);
else {
t+=a[1][1];
}
}
per(i,1,n+1) go(t,a[2][i]);
ans=t;
t=a[1][1];
rep(i,1,n+1) {
if (i%2) {
go(t,a[2][i]);
if (i<n) {
ans = min(ans, t+calc(t,a[2][i+1])+cyc[2][i+1]);
go(t,a[2][i+1]);
} else ans=min(ans,t);
} else {
go(t,a[1][i]);
if (i<n) {
ans = min(ans, t+calc(t,a[1][i+1])+cyc[1][i+1]);
go(t,a[1][i+1]);
} else ans=min(ans,t);
}
}
printf("%lld\n",ans);
}
int main() {
int _;
scanf("%d",&_);
rep(__,0,_) {
//printf("Case #%d: ",__+1);
solve();
}
}