 //#pragma comment(linker, "/stack:247474112")
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// #pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>
using namespace std;

// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;

//typedef tree<
//        pair<int, int>, // change type
//        null_type,
//        less<pair<int, int> >, // change type
//        rb_tree_tag,
//        tree_order_statistics_node_update>
//        ordered_set;

#define     pii             pair<int ,int>
#define     ff              first
#define     ss              second
#define     pb(x)           push_back(x )
#define     mp              make_pair
#define     sz(x)           x.size()
#define     clr(x)          x.clear()
#define     mem(x ,y)       memset(x , y , sizeof x )
#define     all(a )         a.begin() , a.end()
#define     endl            "\n"
#define     si(x )          scanf("%d", &x)
#define     sl(x )          scanf("%I64d", &x)
#define     sd(x )          scanf("%lf", &x)
#define     sii(x,y )       scanf("%d%d", &x,&y)
#define     siii(x,y ,z)    scanf("%d%d%d ", &x,&y , &z)
#define     rep(i ,n )      for(int i = 0 ; i < n ; i++ )
#define     repi(i ,n )     for(int i = 1 ; i <= n ; i++ )
#define     forn(i ,x,n )   for(int i = x ; i <= n ; i++ )
#define     repit(i, c)     for( __typeof((c).begin()) i = (c).begin(); i != (c).end();++i )
#define     dbg(args...)    do {   cerr << #args << ' ' ;  print(args); } while(0); cerr<< endl ;

typedef long long ll  ;
typedef unsigned long long  ull ;
typedef vector<int> vi  ;

const ll  mod =  1e9+7;
const int  inf = 1e9+7  ;
const long long  infL = 1e18 ;

int setbit(int n, int pos  ) { return n = n|(1<< pos) ; }
int resetbit(int n,int pos ) {  return n =  n & ~(1<<pos ); }
bool checkbit(int  n,int pos ) { return (bool ) (n&(1<<pos))  ; }

template < typename T > T mul(T x, T y   ) { x %= mod ; y %= mod ; return (x*y)%mod  ;  }
template < typename T > T add(T x, T y  ) { x %= mod ; y %= mod ; return (x+y)%mod ;  }
template < typename T > T modPow(T x, T k ,T mod ) { if(k == 0 ) return 1; if(k&1  ) { return ( (x%mod)*modPow(x,k-1, mod )%mod )%mod ; } else { T ret = modPow(x,k/2 , mod ) ; ret %= mod ; return (ret*ret )%mod; } }
template < typename T > T ext_gcd(T num1 , T num2, T &X , T &Y ) { T r2,r1, q2, q1 , x2, x1, y2 ,y1 , x,  y, r   ; x2 = 1; y2 = 0;  x1 = 0; y1 = 1; for( r2 =num1 ,r1 = num2 ;r1 != 0 ; y2 = y1, y1 = y,x2 = x1 ,x1 = x ,r2 = r1, r1 = r) {q1 = r2/r1; x = x2 - q1*x1; y = y2 - q1*y1; r = r2%r1 ; } X = x2 ; Y = y2 ; return r2 ;  }
template < typename T > T modInv( T x , T m ) {  return modPow(x,m-2 , m) ; }  // long long ret, t ;// ext_gcd( x, m ,ret ,t  ) ;// ret %= m ;// if(ret<0) ret += m  ; // return ret;}
template < typename T > void print(const T& v) {    cerr << v << ' ' ;}
template < typename T1, typename... T2 > void print( const T1& first, const T2&... rest ){ print(first); print(rest...) ;}
// debuging ...
template < typename F, typename S >
ostream& operator << ( ostream& os, const pair< F, S > & p ) {
    return os << "[ " << p.first << ", " << p.second << " ]";
}

template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v ) {
    os << "[ "; rep(i , sz( v)  )  os << v[i] << ' ' ; return os << " ]" ;
}

//int dx[] = {0 , 0 ,+1, -1 } ;
//int dy[] = {-1, +1,0 , 0 };

const int M = (int )3e5+7;
const int mx = (int)700;
const int nx  = 2000+ 77 ;

////  code from here ...

#define pos 0
#define neg 1

ll a[M+2] ,c[M+ 2 ]  , n  ;
ll  dp[M+2][2],vis[M+2][2] ;
ll func(int id, int pre) {
    if(id<1 or id>n ) return 0;
    if(vis[id][pre ]==1){
        return 1e17;
    }
    vis[id][pre] =1 ;
    ll  &ans = dp[id][pre ] ;
    if(ans!=-1) return ans ;
    ans= 0;
    if(pre ==pos) {

        ans = func(id-a[id],neg)+a[id] ;

    } else  {
        ans = func(id+a[id] ,pos)+a[id] ;

    }

    vis[id][pre ]= 0 ;

    return ans;
}

void solve() {
    int  q, y ,cnt,f= 1 ;
    cin>>n  ;
    forn(i ,2, n) cin>> a[i] ;
    mem(dp , -1) ;
    repi(i , n-1) {
        a[1] = i ;
        ll x = func(i+1,pos)+i;
        //dbg("duck  ") ;
        if(x>1e16) cout << -1 <<endl ;
        else cout << x<<endl ;

    }

}

int main() {

    #ifndef ONLINE_JUDGE
        freopen("in.txt", "r", stdin);
     //   freopen("out.txt", "w", stdout);
    #endif
      ios::sync_with_stdio(false);  cin.tie(0); cout.tie(0);

    int t=1 , c= 0 ; // si( t) ;
    while(t--) {
       // printf("Case %d: ",++c)  ;
        solve() ;
    }

}


 //#pragma comment(linker, "/stack:247474112")
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// #pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>
using namespace std;

// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;

//typedef tree<
//        pair<int, int>, // change type
//        null_type,
//        less<pair<int, int> >, // change type
//        rb_tree_tag,
//        tree_order_statistics_node_update>
//        ordered_set;

#define     pii             pair<int ,int>
#define     ff              first
#define     ss              second
#define     pb(x)           push_back(x )
#define     mp              make_pair
#define     sz(x)           x.size()
#define     clr(x)          x.clear()
#define     mem(x ,y)       memset(x , y , sizeof x )
#define     all(a )         a.begin() , a.end()
#define     endl            "\n"
#define     si(x )          scanf("%d", &x)
#define     sl(x )          scanf("%I64d", &x)
#define     sd(x )          scanf("%lf", &x)
#define     sii(x,y )       scanf("%d%d", &x,&y)
#define     siii(x,y ,z)    scanf("%d%d%d ", &x,&y , &z)
#define     rep(i ,n )      for(int i = 0 ; i < n ; i++ )
#define     repi(i ,n )     for(int i = 1 ; i <= n ; i++ )
#define     forn(i ,x,n )   for(int i = x ; i <= n ; i++ )
#define     repit(i, c)     for( __typeof((c).begin()) i = (c).begin(); i != (c).end();++i )
#define     dbg(args...)    do {   cerr << #args << ' ' ;  print(args); } while(0); cerr<< endl ;

typedef long long ll  ;
typedef unsigned long long  ull ;
typedef vector<int> vi  ;

const ll  mod =  1e9+7;
const int  inf = 1e9+7  ;
const long long  infL = 1e18 ;

int setbit(int n, int pos  ) { return n = n|(1<< pos) ; }
int resetbit(int n,int pos ) {  return n =  n & ~(1<<pos ); }
bool checkbit(int  n,int pos ) { return (bool ) (n&(1<<pos))  ; }

template < typename T > T mul(T x, T y   ) { x %= mod ; y %= mod ; return (x*y)%mod  ;  }
template < typename T > T add(T x, T y  ) { x %= mod ; y %= mod ; return (x+y)%mod ;  }
template < typename T > T modPow(T x, T k ,T mod ) { if(k == 0 ) return 1; if(k&1  ) { return ( (x%mod)*modPow(x,k-1, mod )%mod )%mod ; } else { T ret = modPow(x,k/2 , mod ) ; ret %= mod ; return (ret*ret )%mod; } }
template < typename T > T ext_gcd(T num1 , T num2, T &X , T &Y ) { T r2,r1, q2, q1 , x2, x1, y2 ,y1 , x,  y, r   ; x2 = 1; y2 = 0;  x1 = 0; y1 = 1; for( r2 =num1 ,r1 = num2 ;r1 != 0 ; y2 = y1, y1 = y,x2 = x1 ,x1 = x ,r2 = r1, r1 = r) {q1 = r2/r1; x = x2 - q1*x1; y = y2 - q1*y1; r = r2%r1 ; } X = x2 ; Y = y2 ; return r2 ;  }
template < typename T > T modInv( T x , T m ) {  return modPow(x,m-2 , m) ; }  // long long ret, t ;// ext_gcd( x, m ,ret ,t  ) ;// ret %= m ;// if(ret<0) ret += m  ; // return ret;}
template < typename T > void print(const T& v) {    cerr << v << ' ' ;}
template < typename T1, typename... T2 > void print( const T1& first, const T2&... rest ){ print(first); print(rest...) ;}
// debuging ...
template < typename F, typename S >
ostream& operator << ( ostream& os, const pair< F, S > & p ) {
    return os << "[ " << p.first << ", " << p.second << " ]";
}

template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v ) {
    os << "[ "; rep(i , sz( v)  )  os << v[i] << ' ' ; return os << " ]" ;
}

//int dx[] = {0 , 0 ,+1, -1 } ;
//int dy[] = {-1, +1,0 , 0 };

const int M = (int )3e5+7;
const int mx = (int)700;
const int nx  = 2000+ 77 ;

////  code from here ...

#define pos 0
#define neg 1

ll a[M+2] ,c[M+ 2 ]  , n  ;
ll  dp[M+2][2],vis[M+2][2] ,d =0 ;
ll func(int id, int pre) {
   // dbg(id,pre) ;

    if(id<1 or id>n ) return 0;
    ll  &ans = dp[id][pre ],&x =vis[id][pre] ,t ;

    if(x==d or id==1) ans = -1 ;
    else if(x>0)  {
        x=d;
        if(pre==0) t= func(id-a[id], 1) ;
        else t = func(id+a[id], 0) ;
        ans = (t<0?t: t+a[id]) ;
    }

    return ans;
}

void solve() {
    int  q, y ,cnt,f= 1 ;
    si( n ) ;
    forn(i ,2, n) si( a[i]) ;
   // mem(dp , -1) ;
    repi(i , n-1) {
        ++d ;
      //  a[1] = i ;
        ll x = func(i+1,pos);
        //dbg("duck  ") ;
        printf("%I64d\n" , (x<0?-1: x+i*1LL) ) ;

    }

}

int main() {

    #ifndef ONLINE_JUDGE
        freopen("in.txt", "r", stdin);
     //   freopen("out.txt", "w", stdout);
    #endif
     // ios::sync_with_stdio(false);  cin.tie(0); cout.tie(0);

    int t=1 , c= 0 ; // si( t) ;
    while(t--) {
       // printf("Case %d: ",++c)  ;
        solve() ;
    }

}


 //#pragma comment(linker, "/stack:247474112")
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// #pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>
using namespace std;

// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;

//typedef tree<
//        pair<int, int>, // change type
//        null_type,
//        less<pair<int, int> >, // change type
//        rb_tree_tag,
//        tree_order_statistics_node_update>
//        ordered_set;

#define     pii             pair<int ,int>
#define     ff              first
#define     ss              second
#define     pb(x)           push_back(x )
#define     mp              make_pair
#define     sz(x)           x.size()
#define     clr(x)          x.clear()
#define     mem(x ,y)       memset(x , y , sizeof x )
#define     all(a )         a.begin() , a.end()
#define     endl            "\n"
#define     si(x )          scanf("%d", &x)
#define     sl(x )          scanf("%I64d", &x)
#define     sd(x )          scanf("%lf", &x)
#define     sii(x,y )       scanf("%d%d", &x,&y)
#define     siii(x,y ,z)    scanf("%d%d%d ", &x,&y , &z)
#define     rep(i ,n )      for(int i = 0 ; i < n ; i++ )
#define     repi(i ,n )     for(int i = 1 ; i <= n ; i++ )
#define     forn(i ,x,n )   for(int i = x ; i <= n ; i++ )
#define     repit(i, c)     for( __typeof((c).begin()) i = (c).begin(); i != (c).end();++i )
#define     dbg(args...)    do {   cerr << #args << ' ' ;  print(args); } while(0); cerr<< endl ;

typedef long long ll  ;
typedef unsigned long long  ull ;
typedef vector<int> vi  ;

const ll  mod =  1e9+7;
const int  inf = 1e9+7  ;
const long long  infL = 1e18 ;

int setbit(int n, int pos  ) { return n = n|(1<< pos) ; }
int resetbit(int n,int pos ) {  return n =  n & ~(1<<pos ); }
bool checkbit(int  n,int pos ) { return (bool ) (n&(1<<pos))  ; }

template < typename T > T mul(T x, T y   ) { x %= mod ; y %= mod ; return (x*y)%mod  ;  }
template < typename T > T add(T x, T y  ) { x %= mod ; y %= mod ; return (x+y)%mod ;  }
template < typename T > T modPow(T x, T k ,T mod ) { if(k == 0 ) return 1; if(k&1  ) { return ( (x%mod)*modPow(x,k-1, mod )%mod )%mod ; } else { T ret = modPow(x,k/2 , mod ) ; ret %= mod ; return (ret*ret )%mod; } }
template < typename T > T ext_gcd(T num1 , T num2, T &X , T &Y ) { T r2,r1, q2, q1 , x2, x1, y2 ,y1 , x,  y, r   ; x2 = 1; y2 = 0;  x1 = 0; y1 = 1; for( r2 =num1 ,r1 = num2 ;r1 != 0 ; y2 = y1, y1 = y,x2 = x1 ,x1 = x ,r2 = r1, r1 = r) {q1 = r2/r1; x = x2 - q1*x1; y = y2 - q1*y1; r = r2%r1 ; } X = x2 ; Y = y2 ; return r2 ;  }
template < typename T > T modInv( T x , T m ) {  return modPow(x,m-2 , m) ; }  // long long ret, t ;// ext_gcd( x, m ,ret ,t  ) ;// ret %= m ;// if(ret<0) ret += m  ; // return ret;}
template < typename T > void print(const T& v) {    cerr << v << ' ' ;}
template < typename T1, typename... T2 > void print( const T1& first, const T2&... rest ){ print(first); print(rest...) ;}
// debuging ...
template < typename F, typename S >
ostream& operator << ( ostream& os, const pair< F, S > & p ) {
    return os << "[ " << p.first << ", " << p.second << " ]";
}

template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v ) {
    os << "[ "; rep(i , sz( v)  )  os << v[i] << ' ' ; return os << " ]" ;
}

//int dx[] = {0 , 0 ,+1, -1 } ;
//int dy[] = {-1, +1,0 , 0 };

const int M = (int )3e5+7;
const int mx = (int)700;
const int nx  = 2000+ 77 ;

////  code from here ...

#define pos 0
#define neg 1

ll a[M+2] ,c[M+ 2 ]  , n  ;
ll  dp[M+2][2],vis[M+2][2] ,d =0 ;
ll func(int id, int pre) {
   // dbg(id,pre) ;

    if(id<1 or id>n ) return 0;
    ll  &ans = dp[id][pre ],&x =vis[id][pre] ,t ;

    if(x==d or id==1) ans = -1 ;
    else if(x<d) {
        x=d;
        if(pre==0) t= func(id-a[id], 1) ;
        else t = func(id+a[id], 0) ;
        ans = (t<0?t: t+a[id]) ;
    }

    return ans;
}

void solve() {
    int  q, y ,cnt,f= 1 ;
    si( n ) ;
    forn(i ,2, n) si( a[i]) ;
   // mem(dp , -1) ;
    repi(i , n-1) {
        ++d ;
      //  a[1] = i ;
        ll x = func(i+1,pos);
        //dbg("duck  ") ;
        printf("%I64d\n" , (x<0?-1: x+i*1LL) ) ;

    }

}

int main() {

    #ifndef ONLINE_JUDGE
        freopen("in.txt", "r", stdin);
     //   freopen("out.txt", "w", stdout);
    #endif
     // ios::sync_with_stdio(false);  cin.tie(0); cout.tie(0);

    int t=1 , c= 0 ; // si( t) ;
    while(t--) {
       // printf("Case %d: ",++c)  ;
        solve() ;
    }

}


 //#pragma comment(linker, "/stack:247474112")
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// #pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>
using namespace std;

// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;

//typedef tree<
//        pair<int, int>, // change type
//        null_type,
//        less<pair<int, int> >, // change type
//        rb_tree_tag,
//        tree_order_statistics_node_update>
//        ordered_set;

#define     pii             pair<int ,int>
#define     ff              first
#define     ss              second
#define     pb(x)           push_back(x )
#define     mp              make_pair
#define     sz(x)           x.size()
#define     clr(x)          x.clear()
#define     mem(x ,y)       memset(x , y , sizeof x )
#define     all(a )         a.begin() , a.end()
#define     endl            "\n"
#define     si(x )          scanf("%d", &x)
#define     sl(x )          scanf("%I64d", &x)
#define     sd(x )          scanf("%lf", &x)
#define     sii(x,y )       scanf("%d%d", &x,&y)
#define     siii(x,y ,z)    scanf("%d%d%d ", &x,&y , &z)
#define     rep(i ,n )      for(int i = 0 ; i < n ; i++ )
#define     repi(i ,n )     for(int i = 1 ; i <= n ; i++ )
#define     forn(i ,x,n )   for(int i = x ; i <= n ; i++ )
#define     repit(i, c)     for( __typeof((c).begin()) i = (c).begin(); i != (c).end();++i )
#define     dbg(args...)    do {   cerr << #args << ' ' ;  print(args); } while(0); cerr<< endl ;

typedef long long ll  ;
typedef unsigned long long  ull ;
typedef vector<int> vi  ;

const ll  mod =  1e9+7;
const int  inf = 1e9+7  ;
const long long  infL = 1e18 ;

int setbit(int n, int pos  ) { return n = n|(1<< pos) ; }
int resetbit(int n,int pos ) {  return n =  n & ~(1<<pos ); }
bool checkbit(int  n,int pos ) { return (bool ) (n&(1<<pos))  ; }

template < typename T > T mul(T x, T y   ) { x %= mod ; y %= mod ; return (x*y)%mod  ;  }
template < typename T > T add(T x, T y  ) { x %= mod ; y %= mod ; return (x+y)%mod ;  }
template < typename T > T modPow(T x, T k ,T mod ) { if(k == 0 ) return 1; if(k&1  ) { return ( (x%mod)*modPow(x,k-1, mod )%mod )%mod ; } else { T ret = modPow(x,k/2 , mod ) ; ret %= mod ; return (ret*ret )%mod; } }
template < typename T > T ext_gcd(T num1 , T num2, T &X , T &Y ) { T r2,r1, q2, q1 , x2, x1, y2 ,y1 , x,  y, r   ; x2 = 1; y2 = 0;  x1 = 0; y1 = 1; for( r2 =num1 ,r1 = num2 ;r1 != 0 ; y2 = y1, y1 = y,x2 = x1 ,x1 = x ,r2 = r1, r1 = r) {q1 = r2/r1; x = x2 - q1*x1; y = y2 - q1*y1; r = r2%r1 ; } X = x2 ; Y = y2 ; return r2 ;  }
template < typename T > T modInv( T x , T m ) {  return modPow(x,m-2 , m) ; }  // long long ret, t ;// ext_gcd( x, m ,ret ,t  ) ;// ret %= m ;// if(ret<0) ret += m  ; // return ret;}
template < typename T > void print(const T& v) {    cerr << v << ' ' ;}
template < typename T1, typename... T2 > void print( const T1& first, const T2&... rest ){ print(first); print(rest...) ;}
// debuging ...
template < typename F, typename S >
ostream& operator << ( ostream& os, const pair< F, S > & p ) {
    return os << "[ " << p.first << ", " << p.second << " ]";
}

template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v ) {
    os << "[ "; rep(i , sz( v)  )  os << v[i] << ' ' ; return os << " ]" ;
}

//int dx[] = {0 , 0 ,+1, -1 } ;
//int dy[] = {-1, +1,0 , 0 };

const int M = (int )3e5+7;
const int mx = (int)700;
const int nx  = 2000+ 77 ;

////  code from here ...

#define pos 0
#define neg 1

ll a[M+2] ,c[M+ 2 ]  , n  ;
ll  dp[M+2][2],vis[M+2][2] ,d =0 ;
ll func(int id, int pre) {
   // dbg(id,pre) ;

    if(id<1 or id>n ) return 0;
    ll  &ans = dp[id][pre ],&x =vis[id][pre] ,t ;

    if(x==d or id==1) return ans = -1 ;
    else if(x<d) {
        x=d;
        if(pre==pos) t= func(id-a[id], neg) ;
        else t = func(id+a[id], pos) ;
        ans = (t<0?t: t+a[id]) ;
    }

    return ans;
}

void solve() {
    int  q, y ,cnt,f= 1 ;
    cin>>n  ;
    forn(i ,2, n) cin>> a[i] ;
    mem(dp , -1) ;
    repi(i , n-1) {
        ++d ;
      //  a[1] = i ;
        ll x = func(i+1,pos);
        //dbg("duck  ") ;
        if(x<0) cout << -1 <<endl ;
        else cout << x+i<<endl ;

    }

}

int main() {

    #ifndef ONLINE_JUDGE
        freopen("in.txt", "r", stdin);
     //   freopen("out.txt", "w", stdout);
    #endif
      ios::sync_with_stdio(false);  cin.tie(0); cout.tie(0);

    int t=1 , c= 0 ; // si( t) ;
    while(t--) {
       // printf("Case %d: ",++c)  ;
        solve() ;
    }

}


 //#pragma comment(linker, "/stack:247474112")
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// #pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>
using namespace std;

// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;

//typedef tree<
//        pair<int, int>, // change type
//        null_type,
//        less<pair<int, int> >, // change type
//        rb_tree_tag,
//        tree_order_statistics_node_update>
//        ordered_set;

#define     pii             pair<int ,int>
#define     ff              first
#define     ss              second
#define     pb(x)           push_back(x )
#define     mp              make_pair
#define     sz(x)           x.size()
#define     clr(x)          x.clear()
#define     mem(x ,y)       memset(x , y , sizeof x )
#define     all(a )         a.begin() , a.end()
#define     endl            "\n"
#define     si(x )          scanf("%d", &x)
#define     sl(x )          scanf("%I64d", &x)
#define     sd(x )          scanf("%lf", &x)
#define     sii(x,y )       scanf("%d%d", &x,&y)
#define     siii(x,y ,z)    scanf("%d%d%d ", &x,&y , &z)
#define     rep(i ,n )      for(int i = 0 ; i < n ; i++ )
#define     repi(i ,n )     for(int i = 1 ; i <= n ; i++ )
#define     forn(i ,x,n )   for(int i = x ; i <= n ; i++ )
#define     repit(i, c)     for( __typeof((c).begin()) i = (c).begin(); i != (c).end();++i )
#define     dbg(args...)    do {   cerr << #args << ' ' ;  print(args); } while(0); cerr<< endl ;

typedef long long ll  ;
typedef unsigned long long  ull ;
typedef vector<int> vi  ;

const ll  mod =  1e9+7;
const int  inf = 1e9+7  ;
const long long  infL = 1e18 ;

int setbit(int n, int pos  ) { return n = n|(1<< pos) ; }
int resetbit(int n,int pos ) {  return n =  n & ~(1<<pos ); }
bool checkbit(int  n,int pos ) { return (bool ) (n&(1<<pos))  ; }

template < typename T > T mul(T x, T y   ) { x %= mod ; y %= mod ; return (x*y)%mod  ;  }
template < typename T > T add(T x, T y  ) { x %= mod ; y %= mod ; return (x+y)%mod ;  }
template < typename T > T modPow(T x, T k ,T mod ) { if(k == 0 ) return 1; if(k&1  ) { return ( (x%mod)*modPow(x,k-1, mod )%mod )%mod ; } else { T ret = modPow(x,k/2 , mod ) ; ret %= mod ; return (ret*ret )%mod; } }
template < typename T > T ext_gcd(T num1 , T num2, T &X , T &Y ) { T r2,r1, q2, q1 , x2, x1, y2 ,y1 , x,  y, r   ; x2 = 1; y2 = 0;  x1 = 0; y1 = 1; for( r2 =num1 ,r1 = num2 ;r1 != 0 ; y2 = y1, y1 = y,x2 = x1 ,x1 = x ,r2 = r1, r1 = r) {q1 = r2/r1; x = x2 - q1*x1; y = y2 - q1*y1; r = r2%r1 ; } X = x2 ; Y = y2 ; return r2 ;  }
template < typename T > T modInv( T x , T m ) {  return modPow(x,m-2 , m) ; }  // long long ret, t ;// ext_gcd( x, m ,ret ,t  ) ;// ret %= m ;// if(ret<0) ret += m  ; // return ret;}
template < typename T > void print(const T& v) {    cerr << v << ' ' ;}
template < typename T1, typename... T2 > void print( const T1& first, const T2&... rest ){ print(first); print(rest...) ;}
// debuging ...
template < typename F, typename S >
ostream& operator << ( ostream& os, const pair< F, S > & p ) {
    return os << "[ " << p.first << ", " << p.second << " ]";
}

template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v ) {
    os << "[ "; rep(i , sz( v)  )  os << v[i] << ' ' ; return os << " ]" ;
}

//int dx[] = {0 , 0 ,+1, -1 } ;
//int dy[] = {-1, +1,0 , 0 };

const int M = (int )3e5+7;
const int mx = (int)700;
const int nx  = 2000+ 77 ;

////  code from here ...

#define pos 0
#define neg 1

ll a[M+2] ,c[M+ 2 ]  , n  ;
ll  dp[M+2][2],vis[M+2][2] ,d =0 ;
ll func(int id, int pre) {
   // dbg(id,pre) ;

    if(id<1 or id>n ) return 0;
    ll  &ans = dp[id][pre ],&x =vis[id][pre] ,t ;

    if(x==d or id==1) ans = -1 ;
    else if(x==0)  {
        x=d;
        if(pre==0) t= func(id-a[id], 1) ;
        else t = func(id+a[id], 0) ;
        ans = (t<0?t: t+a[id]) ;
    }

    return ans;
}

void solve() {
    int  q, y ,cnt,f= 1 ;
    si( n ) ;
    forn(i ,2, n) si( a[i]) ;
   // mem(dp , -1) ;
    repi(i , n-1) {
        ++d ;
      //  a[1] = i ;
        ll x = func(i+1,pos);
        //dbg("duck  ") ;
        printf("%I64d\n" , (x<0?-1: x+i*1LL) ) ;

    }

}

int main() {

    #ifndef ONLINE_JUDGE
        freopen("in.txt", "r", stdin);
     //   freopen("out.txt", "w", stdout);
    #endif
     // ios::sync_with_stdio(false);  cin.tie(0); cout.tie(0);

    int t=1 , c= 0 ; // si( t) ;
    while(t--) {
       // printf("Case %d: ",++c)  ;
        solve() ;
    }

}


#include <bits/stdc++.h>

using namespace std;

int n, a[323456];
long long bd[323456];
long long y;
bool used[323456];
bool dfs(int u) {
	//cout<<u<< ' ';
	if(u==1)return 1;
	if(u <= 0 || u > n) return 0 ;
	if(used[u]) {
	    used[u]=0;
		return 1;
	}
	used[u] = 1;

	if(u == 1) {
		used[u]=0;
		return 1;
	}
	y += a[u];
	int to = u + a[u];
	//if(used[to]) return 1;
	bool ok = 0;
	if(to - a[to] <= n && to - a[to]>0)
	ok = dfs(to - a[to]);
	used[u] = 0;
	return ok;
}
int main() {
	cin >> n;
	for(int i = 2; i <= n; i++) cin >> a[i];

	for(int i = 2; i <= n; i++) {
		y = a[i];
		if(dfs(i - a[i])) bd[i] = -1;
		else bd[i] = y;
	}
	for(int i = 1; i <= n - 1;i++) {
		y = i;
		if(bd[i + 1]==-1) cout << -1 << endl;
		else cout << bd[i + 1] + y << endl;

	}
}


#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>

using namespace std;

#define REP(i,n) for((i)=0;(i)<(int)(n);(i)++)
#define snuke(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)

typedef long long ll;
#define INF (1ll<<60)

int N;
int a[200010];
ll dist[400010];
int p[400010];
vector <int> graph[400010];

void dfs(int x, ll d){
    dist[x] = d;
    int i;
    REP(i,graph[x].size()){
        int y = graph[x][i];
        ll d2 = min(d + a[y%N], INF);
        dfs(y, d2);
    }
}

int main(void){
    int i;

    cin >> N;
    REP(i,N-1) scanf("%d", &a[i+1]);

    for(i=1;i<N;i++){
        p[i] = ((i+a[i] < N) ? (N+i+a[i]) : -1);
        p[N+i] = ((i-a[i] >= 0) ? (i-a[i]) : -1);
    }

    for(i=1;i<N;i++){
        if(p[i] != -1) graph[p[i]].push_back(i);
        if(p[N+i] != -1) graph[p[N+i]].push_back(N+i);
    }

    REP(i,2*N) dist[i] = INF;
    dfs(0, INF);
    for(i=1;i<N;i++) if(p[i] == -1) dfs(i, a[i]);
    for(i=1;i<N;i++) if(p[N+i] == -1) dfs(N+i, a[i]);

//  REP(i,2*N) cout << p[i] << endl;

    REP(i,N-1){
        ll ans = dist[N+i+1];
        if(ans == INF){
            ans = -1;
        } else {
            ans += i + 1;
        }
        printf("%I64d\n", ans);
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int n, a[323456];
long long bd[323456];
long long y;
bool used[323456];
bool dfs(int u) {
	//cout<<u<< ' ';
	//if(u==1)return 1;
	if(u <= 0 || u > n) return 0 ;
	if(used[u]) {
	    used[u]=0;
	    //bd[u]=-1;
		return 1;
	}
	used[u] = 1;

	if(u == 1) {
		used[u]=0;
		return 1;
	}
	int zet = y;
	y += a[u];
	int to = u + a[u];
	//if(used[to]) return 1;
	bool ok = 0;
	if(to > 0 && to <= n && to - a[to] <= n && to - a[to]>0)
	ok = dfs(to - a[to]);
	used[u] = 0;
	if(ok==1)bd[to]=-1;
	bd[u]=y-zet=a[u];
	return ok;
}
int main() {
	cin >> n;
	for(int i = 2; i <= n; i++) cin >> a[i];

	for(int i = 2; i <= n; i++) {
		y = a[i];
		if(bd[i]==-1)continue;
		if(bd[i]!=0)continue;
		if(dfs(i - a[i])) bd[i] = -1;
		else bd[i] = y;
	}
	for(int i = 1; i <= n - 1;i++) {
		y = i;
		if(bd[i + 1]==-1) cout << -1 << endl;
		else cout << bd[i + 1] + y << endl;

	}
}


#include <bits/stdc++.h>

using namespace std;

int n, a[323456];
long long bd[323456];
long long y;
bool used[323456];
bool dfs(int u) {
	//cout<<u<< ' ';
	if(u==1)return 1;
	if(u <= 0 || u > n) return 0 ;
	if(used[u]) {
	    used[u]=0;
		return 1;
	}
	used[u] = 1;

	if(u == 1) {
		used[u]=0;
		return 1;
	}
	y += a[u];
	int to = u + a[u];
	//if(used[to]) return 1;
	bool ok = 0;
	if(to > 0 && to <= n && to - a[to] <= n && to - a[to]>0)
	ok = dfs(to - a[to]);
	used[u] = 0;
	return ok;
}
int main() {
	cin >> n;
	for(int i = 2; i <= n; i++) cin >> a[i];

	for(int i = 2; i <= n; i++) {
		y = a[i];
		if(dfs(i - a[i])) bd[i] = -1;
		else bd[i] = y;
	}
	for(int i = 1; i <= n - 1;i++) {
		y = i;
		if(bd[i + 1]==-1) cout << -1 << endl;
		else cout << bd[i + 1] + y << endl;

	}
}


#include <bits/stdc++.h>

using namespace std;

int n, a[123456];
int bd[123456];
int y;
bool used[123456];
bool dfs(int u) {
	//cout<<u<< ' ';
	if(u==1)return 1;
	if(u <= 0 || u > n) return 0 ;
	if(used[u]) {
	    used[u]=0;
		return 1;
	}
	used[u] = 1;

	if(u == 1) {
		used[u]=0;
		return 1;
	}
	y += a[u];
	int to = u + a[u];
	//if(used[to]) return 1;
	bool ok = 0;
	if(to - a[to] <= n && to - a[to]>0)
	ok = dfs(to - a[to]);
	used[u] = 0;
	return ok;
}
int main() {
	cin >> n;
	for(int i = 2; i <= n; i++) cin >> a[i];

	for(int i = 2; i <= n; i++) {
		y = a[i];
		if(dfs(i - a[i])) bd[i] = -1;
		else bd[i] = y;
	}
	for(int i = 1; i <= n - 1;i++) {
		y = i;
		if(bd[i + 1]==-1) cout << -1 << endl;
		else cout << bd[i + 1] + y << endl;

	}
}


#include <bits/stdc++.h>

using namespace std;

int n, a[323456];
long long bd[323456];
long long y;
bool used[323456];
bool dfs(int u) {
	//cout<<u<< ' ';
	//if(u==1)return 1;
	if(u <= 0 || u > n) return 0 ;
	if(used[u]) {
	    used[u]=0;
	    //bd[u]=-1;
		return 1;
	}
	used[u] = 1;

	if(u == 1) {
		used[u]=0;
		return 1;
	}
	int zet = y;
	y += a[u];
	int to = u + a[u];
	//if(used[to]) return 1;
	bool ok = 0;
	if(to > 0 && to <= n && to - a[to] <= n && to - a[to]>0)
	ok = dfs(to - a[to]);
	used[u] = 0;
	if(ok==1)bd[to]=-1;
	bd[u]=y-zet;
	return ok;
}
int main() {
	cin >> n;
	for(int i = 2; i <= n; i++) cin >> a[i];

	for(int i = 2; i <= n; i++) {
		y = a[i];
		if(bd[i]==-1)continue;
		if(bd[i]!=0)continue;
		if(dfs(i - a[i])) bd[i] = -1;
		else bd[i] = y;
	}
	for(int i = 1; i <= n - 1;i++) {
		y = i;
		if(bd[i + 1]==-1) cout << -1 << endl;
		else cout << bd[i + 1] + y << endl;

	}
}


#include <bits/stdc++.h>

using namespace std;

int n, a[323456];
long long bd[323456];
long long y;
bool used[323456];
bool dfs(int u) {
	//cout<<u<< ' ';
	//if(u==1)return 1;
	if(u <= 0 || u > n) return 0 ;
	if(used[u]) {
	    used[u]=0;
	    //bd[u]=-1;
		return 1;
	}
	used[u] = 1;

	if(u == 1) {
		used[u]=0;
		return 1;
	}
	int zet = y;
	y += a[u];
	int to = u + a[u];
	//if(used[to]) return 1;
	bool ok = 0;
	if(to > 0 && to <= n && to - a[to] <= n && to - a[to]>0)
	ok = dfs(to - a[to]);
	used[u] = 0;
	if(ok==1)bd[to]=-1;
	bd[u]=y-zet-a[u];
	return ok;
}
int main() {
	cin >> n;
	for(int i = 2; i <= n; i++) cin >> a[i];

	for(int i = 2; i <= n; i++) {
		y = a[i];
		if(bd[i]==-1)continue;
		if(bd[i]!=0)continue;
		if(dfs(i - a[i])) bd[i] = -1;
		else bd[i] = y;
	}
	for(int i = 1; i <= n - 1;i++) {
		y = i;
		if(bd[i + 1]==-1) cout << -1 << endl;
		else cout << bd[i + 1] + y << endl;

	}
}


#include <bits/stdc++.h>

using namespace std;

int n, a[123456];
int bd[123456];
int y;
bool used[123456];
bool dfs(int u) {
	if(u <= 0 || u > n) return 0 ;
	used[u] = 1;

	if(u == 1) {
		return 1;
	}
	y += a[u];
	int to = u + a[u];
	if(used[to]) return 1;
	bool ok = dfs(to);
	used[u] = 0;
	return ok;
}
int main() {
	cin >> n;
	for(int i = 2; i <= n; i++) cin >> a[i];

	for(int i = 2; i <= n; i++) {
		y = a[i];
		if(dfs(i - a[i])) bd[i] = -1;
		else bd[i] = y;
	}
	for(int i = 1; i <= n - 1;i++) {
		y = i;
		if(bd[i + 1]==-1) cout << -1 << endl;
		else cout << bd[i + 1] + y << endl;

	}
}


#include <bits/stdc++.h>

using namespace std;

int n, a[323456];
long long bd[323456];
long long y;
bool used[323456];
bool dfs(int u) {
	//cout<<u<< ' ';
	//if(u==1)return 1;
	if(u <= 0 || u > n) return 0 ;
	if(used[u]) {
	    used[u]=0;
	    //bd[u]=-1;
		return 1;
	}
	used[u] = 1;

	if(u == 1) {
		used[u]=0;
		return 1;
	}
	y += a[u];
	int to = u + a[u];
	//if(used[to]) return 1;
	bool ok = 0;
	if(to > 0 && to <= n && to - a[to] <= n && to - a[to]>0)
	ok = dfs(to - a[to]);
	used[u] = 0;
	if(ok==1)bd[to]=-1;
	return ok;
}
int main() {
	cin >> n;
	for(int i = 2; i <= n; i++) cin >> a[i];

	for(int i = 2; i <= n; i++) {
		y = a[i];
		if(bd[i]==-1)continue;
		if(dfs(i - a[i])) bd[i] = -1;
		else bd[i] = y;
	}
	for(int i = 1; i <= n - 1;i++) {
		y = i;
		if(bd[i + 1]==-1) cout << -1 << endl;
		else cout << bd[i + 1] + y << endl;

	}
}


#include <bits/stdc++.h>

using namespace std;

int n, a[223456];
int bd[223456];
int y;
bool used[123456];
bool dfs(int u) {
	//cout<<u<< ' ';
	if(u==1)return 1;
	if(u <= 0 || u > n) return 0 ;
	if(used[u]) {
	    used[u]=0;
		return 1;
	}
	used[u] = 1;

	if(u == 1) {
		used[u]=0;
		return 1;
	}
	y += a[u];
	int to = u + a[u];
	//if(used[to]) return 1;
	bool ok = 0;
	if(to - a[to] <= n && to - a[to]>0)
	ok = dfs(to - a[to]);
	used[u] = 0;
	return ok;
}
int main() {
	cin >> n;
	for(int i = 2; i <= n; i++) cin >> a[i];

	for(int i = 2; i <= n; i++) {
		y = a[i];
		if(dfs(i - a[i])) bd[i] = -1;
		else bd[i] = y;
	}
	for(int i = 1; i <= n - 1;i++) {
		y = i;
		if(bd[i + 1]==-1) cout << -1 << endl;
		else cout << bd[i + 1] + y << endl;

	}
}


/* 2018-05-04-14.57.58*/

#include<bits/stdc++.h>
#define ll long long int
#define N 100010
using namespace std;

int A[N],visited[N],n;
ll dp[N];

bool run(int i)
{
    if(visited[i]==1) return false;
    if(visited[i]==2) return true;
    visited[i]=1;
    int temp=i;
    dp[i]=(ll)A[i];
    temp-=A[i];
    if(temp<=0) return true;
    dp[i]+=(ll)A[temp];
    temp+=A[temp];
    if(temp>n) return true;
    bool key=run(temp);
    if(key) visited[i]=2;
    else dp[i]=-1;
    return key;
}

int main()
{
    scanf("%d",&n);
    for(int i=2;i<=n;i++) scanf("%d",&A[i]);
    for(int i=0;i<=n;i++) dp[i]=0,visited[i]=0;
    visited[1]=1;
    for(int i=2;i<=n;i++) run(i);
    for(int i=2;i<=n;i++)
    {
        if(dp[i]!=-1) dp[i]+=(ll)(i-1);
        printf("%lld\n",dp[i]);
    }
    return 0;
}


/* 2018-05-04-14.57.58*/

#include<bits/stdc++.h>
#define ll long long int
#define N 200010
using namespace std;

int A[N],visited[N],n;
ll dp[N];

bool run(int i)
{
    if(visited[i]==1) return false;
    if(visited[i]==2) return true;
    visited[i]=1;
    int temp=i;
    dp[i]=(ll)A[i];
    temp-=A[i];
    if(temp<=0) return true;
    dp[i]+=(ll)A[temp];
    temp+=A[temp];
    if(temp>n) return true;
    bool key=run(temp);
    if(key) visited[i]=2;
    else dp[i]=-1;
    return key;
}

int main()
{
    scanf("%d",&n);
    for(int i=2;i<=n;i++) scanf("%d",&A[i]);
    for(int i=0;i<=n;i++) dp[i]=0,visited[i]=0;
    visited[1]=1;
    for(int i=2;i<=n;i++) run(i);
    for(int i=2;i<=n;i++)
    {
        if(dp[i]!=-1) dp[i]+=(ll)(i-1);
        printf("%lld\n",dp[i]);
    }
    return 0;
}


/* 2018-05-04-14.57.58*/

#include<bits/stdc++.h>
#define ll long long int
#define N 200010
using namespace std;

int A[N],visited[N],n;
ll dp[N];

bool run(int i)
{
    if(visited[i]==1) return false;
    if(visited[i]==2) return true;
    visited[i]=1;
    int temp=i;
    dp[i]=(ll)A[i];
    temp-=A[i];
    if(temp<=0) return true;
    dp[i]+=(ll)A[temp];
    temp+=A[temp];
    if(temp>n) return true;
    bool key=run(temp);
    if(key) dp[i]+=dp[temp],visited[i]=2;
    else dp[i]=-1;
    return key;
}

int main()
{
    scanf("%d",&n);
    for(int i=2;i<=n;i++) scanf("%d",&A[i]);
    for(int i=0;i<=n;i++) dp[i]=0,visited[i]=0;
    visited[1]=1;
    for(int i=2;i<=n;i++) run(i);
    for(int i=2;i<=n;i++)
    {
        if(dp[i]!=-1) dp[i]+=(ll)(i-1);
        printf("%lld\n",dp[i]);
    }
    return 0;
}


#include <algorithm>
#include <iostream>
#include <vector>

template<typename T>
T read() {
  T t;
  std::cin >> t;
  return t;
}

auto read_vector(int length) {
  std::vector<int> vector;
  while (length-- != 0) {
    vector.push_back(read<int>());
  }
  return vector;
}

size_t calculate_alignment_steps(
    int oranges, int candies, int oranges_min, int candies_min
)
{
  int oranges_diff = oranges - oranges_min;
  int candies_diff = candies - candies_min;
  int steps = std::max(oranges_diff, candies_diff);
  return steps;
}

size_t solve(std::vector<int>&& oranges, std::vector<int>&& candies)
{
    int oranges_min = *std::min_element(oranges.begin(), oranges.end());
    int candies_min = *std::min_element(candies.begin(), candies.end());

    // both oranges and candies have always equal length
    const auto length = oranges.size();
    size_t steps_number = 0;

    for (size_t i = 0; i < length; i++)
    {
      steps_number += calculate_alignment_steps(
          oranges[i],
          candies[i],
          oranges_min,
          candies_min
      );
    }
    return steps_number;
}

int main(int argc, char const *argv[]) {
  auto tests_number = read<int>();

  while (tests_number-- != 0) {
    auto presents_number = read<int>();
    auto candies = read_vector(presents_number);
    auto oranges = read_vector(presents_number);

    const auto moves_number = solve(std::move(oranges), std::move(candies));
    std::cout << moves_number << std::endl;
  }

  return 0;
}


#include <algorithm>
#include <iostream>
#include <vector>
#include <cstdint>

template<typename T>
T read() {
  T t;
  std::cin >> t;
  return t;
}

std::vector<uintmax_t> read_vector(uintmax_t length) {
  std::vector<uintmax_t> vector;
  while (length-- != 0) {
    vector.push_back(read<uintmax_t>());
  }
  return vector;
}

uintmax_t calculate_alignment_steps(
    uintmax_t oranges, uintmax_t candies, uintmax_t oranges_min, uintmax_t candies_min
)
{
  uintmax_t oranges_diff = oranges - oranges_min;
  uintmax_t candies_diff = candies - candies_min;
  uintmax_t steps = std::max(oranges_diff, candies_diff);
  return steps;
}

uintmax_t solve(std::vector<uintmax_t>&& oranges, std::vector<uintmax_t>&& candies)
{
    uintmax_t oranges_min = *std::min_element(oranges.begin(), oranges.end());
    uintmax_t candies_min = *std::min_element(candies.begin(), candies.end());

    // both oranges and candies have always equal length`
    const auto length = oranges.size();
    uintmax_t steps_number = 0;

    for (size_t i = 0; i < length; i++)
    {
      steps_number += calculate_alignment_steps(
          oranges.at(i),
          candies.at(i),
          oranges_min,
          candies_min
      );
    }

    return steps_number;
}

int main(int argc, char const *argv[]) {
  auto tests_number = read<uintmax_t>();

  while (tests_number-- != 0) {
    auto presents_number = read<uintmax_t>();
    auto candies = read_vector(presents_number);
    auto oranges = read_vector(presents_number);

    const auto moves_number = solve(std::move(oranges), std::move(candies));
    std::cout << moves_number << std::endl;
  }

  return 0;
}


#include <algorithm>
#include <iostream>
#include <vector>

template<typename T>
T read() {
  T t;
  std::cin >> t;
  return t;
}

auto read_vector(long long length) {
  std::vector<long long> vector;
  while (length-- != 0) {
    vector.push_back(read<long long>());
  }
  return vector;
}

long long calculate_alignment_steps(
    long long oranges, long long candies, long long oranges_min, long long candies_min
)
{
  long long oranges_diff = oranges - oranges_min;
  long long candies_diff = candies - candies_min;
  long long steps = std::max(oranges_diff, candies_diff);
  return steps;
}

size_t solve(std::vector<long long>&& oranges, std::vector<long long>&& candies)
{
    long long oranges_min = *std::min_element(oranges.begin(), oranges.end());
    long long candies_min = *std::min_element(candies.begin(), candies.end());

    // both oranges and candies have always equal length
    const auto length = oranges.size();
    long long steps_number = 0;

    for (size_t i = 0; i < length; i++)
    {
      steps_number += calculate_alignment_steps(
          oranges[i],
          candies[i],
          oranges_min,
          candies_min
      );
    }

    return steps_number;
}

int main(int argc, char const *argv[]) {
  auto tests_number = read<long long>();

  while (tests_number-- != 0) {
    auto presents_number = read<long long>();
    auto candies = read_vector(presents_number);
    auto oranges = read_vector(presents_number);

    const auto moves_number = solve(std::move(oranges), std::move(candies));
    std::cout << moves_number << std::endl;
  }

  return 0;
}


#include <algorithm>
#include <iostream>
#include <vector>
#include <cstdint>

template<typename T>
T read() {
  T t;
  std::cin >> t;
  return t;
}

std::vector<uintmax_t> read_vector(uintmax_t length) {
  std::vector<uintmax_t> vector;
  while (length-- != 0) {
    vector.push_back(read<uintmax_t>());
  }
  return vector;
}

uintmax_t calculate_alignment_steps(
    uintmax_t oranges, uintmax_t candies, uintmax_t oranges_min, uintmax_t candies_min
)
{
  uintmax_t oranges_diff = oranges - oranges_min;
  uintmax_t candies_diff = candies - candies_min;
  uintmax_t steps = std::max(oranges_diff, candies_diff);
  return steps;
}

size_t solve(std::vector<uintmax_t>&& oranges, std::vector<uintmax_t>&& candies)
{
    uintmax_t oranges_min = *std::min_element(oranges.begin(), oranges.end());
    uintmax_t candies_min = *std::min_element(candies.begin(), candies.end());

    // both oranges and candies have always equal length`
    const auto length = oranges.size();
    uintmax_t steps_number = 0;

    for (size_t i = 0; i < length; i++)
    {
      steps_number += calculate_alignment_steps(
          oranges[i],
          candies[i],
          oranges_min,
          candies_min
      );
    }

    return steps_number;
}

int main(int argc, char const *argv[]) {
  auto tests_number = read<uintmax_t>();

  while (tests_number-- != 0) {
    auto presents_number = read<uintmax_t>();
    auto candies = read_vector(presents_number);
    auto oranges = read_vector(presents_number);

    const auto moves_number = solve(std::move(oranges), std::move(candies));
    std::cout << moves_number << std::endl;
  }

  return 0;
}


#include <bits/stdc++.h>
using namespace std;
int mini(vector<int> a){
	int min=15555;
	for(int i=0;i<a.size();i++){
		if(a[i]<min){
			min=a[i];
		}
	}
	return min;
}
int main(){
//By:DavidYQ
	ios::sync_with_stdio(0);
	cin.tie(NULL);
	int n,t;
	long long a,b;
	cin>>n;

	for(int i=0;i<n;i++){
		vector<int> a1;
		vector<int> a2;
		cin>>t;
		for(int j=0;j<t;j++){
			cin>>a;
			a1.push_back(a);
		}
		for(int k=0;k<t;k++){
			cin>>b;
			a2.push_back(b);
		}
		long long mina=mini(a1);
		long long minb=mini(a2);
		long long cont=0;
		for(int v=0;v<t;v++){
			while(a1[v]>mina){
				if(a2[v]>minb){
					a1[v]--;
					a2[v]--;
					cont++;
				}
				else if(a2[v]==minb){
					cont=cont+(a1[v]-mina);
					a1[v]=mina;
				}
				else{
					a1[v]--;
					cont++;
				}
			}
			while(a2[v]>minb){
				cont=cont+(a2[v]-minb);
				a2[v]=minb;
			}
		}
		cout<<cont<<"\n";
	}
return 0;
}


#include <bits/stdc++.h>
using namespace std;
long long  mini(vector<long long > a){
	long long min=LONG_MAX;
	for(int i=0;i<a.size();i++){
		if(a[i]<min){
			min=a[i];
		}
	}
	return  min;
}

int main(){
//By:DavidYQ
	ios::sync_with_stdio(0);
	cin.tie(NULL);
	int n,t;
	long long a,b;
	cin>>n;

	for(int i=0;i<n;i++){
		vector<long long> a1;
		vector<long long> a2;
		cin>>t;
		for(int j=0;j<t;j++){
			cin>>a;
			a1.push_back(a);
		}
		for(int k=0;k<t;k++){
			cin>>b;
			a2.push_back(b);
		}
		long long mina=mini(a1);
		long long minb=mini(a2);
		long long cont=0;
		for(int v=0;v<t;v++){
			long long res1,res2;
			res1=a1[v]-mina;
			res2=a2[v]-minb;
			if(res1>res2){
				cont =cont+(res1);
			}
			else{
				cont=cont+(res2);
			}
		}
		cout<<cont<<"\n";
	}
return 0;
}


#include <bits/stdc++.h>
using namespace std;
int mini(vector<int> a){
	int min=15555;
	for(int i=0;i<a.size();i++){
		if(a[i]<min){
			min=a[i];
		}
	}
	return min;
}
int minimo(int a, int b){
	int max;
	if(a>b){
		max=a;
	}
	else{
		max=b;
	}
}
int main(){
//By:DavidYQ
	ios::sync_with_stdio(0);
	cin.tie(NULL);
	int n,t;
	long long a,b;
	cin>>n;

	for(int i=0;i<n;i++){
		vector<int> a1;
		vector<int> a2;
		cin>>t;
		for(int j=0;j<t;j++){
			cin>>a;
			a1.push_back(a);
		}
		for(int k=0;k<t;k++){
			cin>>b;
			a2.push_back(b);
		}
		long long mina=mini(a1);
		long long minb=mini(a2);
		long long cont=0;
		for(int v=0;v<n;v++){
			int res1,res2;
			res1=a1[v]-mina;
			res2=a2[v]-minb;
			if(res1>res2){
				cont =cont+(res1);
			}
			else{
				cont=cont+(res2);
			}
		}
		cout<<cont<<"\n";
	}
return 0;
}


#include <bits/stdc++.h>
using namespace std;
int mini(vector<int> a){
	int min=15555;
	for(int i=0;i<a.size();i++){
		if(a[i]<min){
			min=a[i];
		}
	}
	return min;
}
int main(){
//By:DavidYQ
	ios::sync_with_stdio(0);
	cin.tie(NULL);
	int n,t;
	long long a,b;
	cin>>n;

	for(int i=0;i<n;i++){
		vector<int> a1;
		vector<int> a2;
		cin>>t;
		for(int j=0;j<t;j++){
			cin>>a;
			a1.push_back(a);
		}
		for(int k=0;k<t;k++){
			cin>>b;
			a2.push_back(b);
		}
		long long mina=mini(a1);
		long long minb=mini(a2);
		long long cont=0;
		for(int v=0;v<t;v++){
			while(a1[v]>mina){
				if(a2[v]>minb){
					a1[v]--;
					a2[v]--;
					cont++;
				}
				else if(a2[v]==minb){
					cont=cont+(a1[v]-mina);
					a1[v]=mina;
				}
				else{
					a1[v]--;
					cont++;
				}
			}
			while(a2[v]>minb){
				a2[v]--;
				cont++;
			}
		}
		cout<<cont<<"\n";
	}
return 0;
}


#include <bits/stdc++.h>
using namespace std;
int mini(vector<int> a){
	int min=15555;
	for(int i=0;i<a.size();i++){
		if(a[i]<min){
			min=a[i];
		}
	}
	return min;
}
int minimo(int a, int b){
	int max;
	if(a>b){
		max=a;
	}
	else{
		max=b;
	}
}
int main(){
//By:DavidYQ
	ios::sync_with_stdio(0);
	cin.tie(NULL);
	int n,t;
	long long a,b;
	cin>>n;

	for(int i=0;i<n;i++){
		vector<int> a1;
		vector<int> a2;
		cin>>t;
		for(int j=0;j<t;j++){
			cin>>a;
			a1.push_back(a);
		}
		for(int k=0;k<t;k++){
			cin>>b;
			a2.push_back(b);
		}
		long long mina=mini(a1);
		long long minb=mini(a2);
		long long cont=0;
		for(int v=0;v<t;v++){
			long long res1,res2;
			res1=a1[v]-mina;
			res2=a2[v]-minb;
			if(res1>res2){
				cont =cont+(res1);
			}
			else{
				cont=cont+(res2);
			}
		}
		cout<<cont<<"\n";
	}
return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int t;cin>>t;
	while(t--)
	{
		int n;cin>>n;
	vector<int>a(n);vector<int>b(n);
		for(int i=0;i<n;i++)cin>>a[i];
		for(int i=0;i<n;i++)cin>>b[i];

		int minic=*min_element(a.begin(),a.end());
			int minio=*min_element(b.begin(),b.end());
			int move=0;
			for(int i=0;i<n;i++)
			{
			    if(a[i]!=minic&&b[i]!=minio)move+=abs(a[i]-minic)+abs(b[i]-minio);
			    else if(a[i]!=minic)move+=abs(a[i]-minic);
			    else if(b[i]!=minio)move+=abs(b[i]-minio);
			    else continue;
			}

			cout<<move<<endl;
	}
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int t;cin>>t;
	while(t--)
	{
		int n;cin>>n;
	vector<int>a(n);vector<int>b(n);
		int b[n];
		for(int i=0;i<n;i++)cin>>a[i];
		for(int i=0;i<n;i++)cin>>b[i];

		int minic=*min_element(a.begin(),a.end());
			int minio=*min_element(b.begin(),b.end());
			int move=0;
			for(int i=0;i<n;i++)
			{
			    if(a[i]!=minic&&b[i]!=minio)move+=abs(a[i]-minic)+abs(b[i]-minio);
			    else if(a[i]!=minic)move+=abs(a[i]-minic);
			    else if(b[i]!=minio)move+=abs(b[i]-minio);
			    else continue;
			}

			cout<<move<<endl;
	}
}


#include<bits/stdc++.h>
using namespace std;
#define int long long int
int32_t main()
{
	int t;cin>>t;
	while(t--)
	{
		int n;cin>>n;
	vector<int>a(n);vector<int>b(n);
		for(int i=0;i<n;i++)cin>>a[i];
		for(int i=0;i<n;i++)cin>>b[i];

		int minic=*min_element(a.begin(),a.end());
			int minio=*min_element(b.begin(),b.end());
			int move=0;
			for(int i=0;i<n;i++)
			{
			    if(a[i]!=minic&&b[i]!=minio)
			    {
			    	if(a[i]<b[i])move+=abs(b[i]-minio);
			    	else move+=abs(a[i]-minic);
				}
			    else if(a[i]!=minic&&b[i]==minio)move+=abs(a[i]-minic);
			    else if(b[i]!=minio&&a[i]==minic)move+=abs(b[i]-minio);
			    else continue;
			}

			cout<<move<<endl;
	}
}


#include<bits/stdc++.h>
using namespace std;
#define int long long int
int32_t main()
{
	int t;cin>>t;
	while(t--)
	{
		int n;cin>>n;
	vector<int>a(n);vector<int>b(n);
		for(int i=0;i<n;i++)cin>>a[i];
		for(int i=0;i<n;i++)cin>>b[i];

		int minic=*min_element(a.begin(),a.end());
			int minio=*min_element(b.begin(),b.end());
			int move=0;
			for(int i=0;i<n;i++)
			{
			    if(a[i]!=minic&&b[i]!=minio)
			    {
			    	int f=abs(a[i]-minic);
			    	int s=abs(b[i]-minio);
			    	if(f>=s)move+=f;
			    	else move+=s;

				}
			    else if(a[i]!=minic&&b[i]==minio)move+=abs(a[i]-minic);
			    else if(b[i]!=minio&&a[i]==minic)move+=abs(b[i]-minio);
			    else continue;
			}

			cout<<move<<endl;
	}
}


#include<bits/stdc++.h>
using namespace std;
#define int long long int
int32_t main()
{
	int t;cin>>t;
	while(t--)
	{
		int n;cin>>n;
	vector<int>a(n);vector<int>b(n);
		for(int i=0;i<n;i++)cin>>a[i];
		for(int i=0;i<n;i++)cin>>b[i];

		int minic=*min_element(a.begin(),a.end());
			int minio=*min_element(b.begin(),b.end());
			int move=0;
			for(int i=0;i<n;i++)
			{
			    if(a[i]!=minic&&b[i]!=minio)
			    {
			    	if(a[i]<b[i])move+=abs(b[i]-minio);
			    	else move+=abs(a[i]-minic);
				}
			    else if(a[i]!=minic)move+=abs(a[i]-minic);
			    else if(b[i]!=minio)move+=abs(b[i]-minio);
			    else continue;
			}

			cout<<move<<endl;
	}
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int t;cin>>t;
	while(t--)
	{
		int n;cin>>n;
	vector<int>a(n);vector<int>b(n);
		for(int i=0;i<n;i++)cin>>a[i];
		for(int i=0;i<n;i++)cin>>b[i];

		int minic=*min_element(a.begin(),a.end());
			int minio=*min_element(b.begin(),b.end());
			int move=0;
			for(int i=0;i<n;i++)
			{
			    if(a[i]!=minic&&b[i]!=minio)
			    {
			    	if(a[i]<b[i])move+=abs(b[i]-minio);
			    	else move+=abs(a[i]-minic);
				}
			    else if(a[i]!=minic)move+=abs(a[i]-minic);
			    else if(b[i]!=minio)move+=abs(b[i]-minio);
			    else continue;
			}

			cout<<move<<endl;
	}
}


#include <bits/stdc++.h>

using namespace std;

#define ar array
#define long long long

const int MAX_N = 1e5 + 1;
const int MOD = 1e9 + 7;
const int INF = 1e9;
const long LINF = 1e18;

void solve() {
	int smallestCandy{INF}, smallestOrange{INF}, n;
	cin >> n;
	if(n == 1){
		cout << "0\n";
		return;
	}
	int temp;
	vector<int> candy, orange;
	for(int i{}; i < n; ++i){
		cin >> temp;
		smallestCandy = min(smallestCandy, temp);
		candy.push_back(temp);
	}
	for(int i{}; i < n; ++i){

		cin >> temp;
		smallestOrange = min(smallestOrange, temp);
		orange.push_back(temp);
	}
	long output{};
	int cdiff, odiff;
	for(int i{}; i < n; ++i){
		cdiff = candy[i] - smallestCandy;
		odiff = orange[i] - smallestOrange;
		output += min(cdiff, odiff) + abs(cdiff - odiff);
	}
	cout << output << '\n';
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);

    int tc; cin >> tc;
    for (int t = 1; t <= tc; t++) {
        // cout << "Case #" << t  << ": ";
        solve();
    }
}


#include <bits/stdc++.h>

using namespace std;

#define ar array
#define ll long long

const int MAX_N = 1e5 + 1;
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll LINF = 1e18;

void solve() {
	int smallestCandy = INF;
	int smallestOrange = INF;
	int n;
	cin >> n;
	if(n == 1){
		cout << "0\n";
		return;
	}
	int temp;
	vector<int> candy{}, orange{};
	for(int i{}; i < n; ++i){
		cin >> temp;
		smallestCandy = min(smallestCandy, temp);
		candy.push_back(temp);
	}
	for(int i{}; i < n; ++i){
		cin >> temp;
		smallestOrange = min(smallestOrange, temp);
		orange.push_back(temp);
	}
	ll output{};
	ll cdiff, odiff;
	for(int i{}; i < n; ++i){
		cdiff = candy[i] - smallestCandy;
		odiff = orange[i] - smallestOrange;
		output += min(cdiff, odiff) + abs(cdiff - odiff);
	}
	cout << output << '\n';
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);

    int tc; cin >> tc;
    for (int t = 1; t <= tc; t++) {
        // cout << "Case #" << t  << ": ";
        solve();
    }
}


#include <bits/stdc++.h>

using namespace std;

#define ar array
#define ll long long

const int MAX_N = 1e5 + 1;
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll LINF = 1e18;

void solve() {
	ll smallestCandy{LINF}, smallestOrange{LINF}, n;
	cin >> n;
	if(n == 1){
		cout << 0;
		return;
	}
	vector<int> candy, orange;
	for(int i{}; i < n; ++i){
		ll temp;
		cin >> temp;
		smallestCandy = min(smallestCandy, temp);
		candy.push_back(temp);
	}
	for(int i{}; i < n; ++i){
		ll temp;
		cin >> temp;
		smallestOrange = min(smallestOrange, temp);
		orange.push_back(temp);
	}
	ll output{};
	for(int i{}; i < n; ++i){
		ll cdiff, odiff;
		cdiff = candy[i] - smallestCandy;
		odiff = orange[i] - smallestOrange;
		output += min(cdiff, odiff) + abs(cdiff - odiff);
	}
	cout << output << '\n';
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);

    int tc; cin >> tc;
    for (int t = 1; t <= tc; t++) {
        // cout << "Case #" << t  << ": ";
        solve();
    }
}


#include <bits/stdc++.h>

using namespace std;

#define ar array
#define ll long long

const int MAX_N = 1e5 + 1;
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll LINF = 1e18;

void solve() {
	int smallestCandy = INF;
	int smallestOrange = INF;
	int n;
	cin >> n;
	if(n == 1){
		cout << "0\n";
		return;
	}
	int temp;
	vector<int> candy(n), orange(n);
	for(int i{}; i < n; ++i){
		cin >> temp;
		smallestCandy = min(smallestCandy, temp);
		candy[i] = (temp);
	}
	for(int i{}; i < n; ++i){
		cin >> temp;
		smallestOrange = min(smallestOrange, temp);
		orange[i] = (temp);
	}
	ll output{};
	ll cdiff, odiff;
	for(int i{}; i < n; ++i){
		cdiff = candy[i] - smallestCandy;
		odiff = orange[i] - smallestOrange;
		output += min(cdiff, odiff) + abs(cdiff - odiff);
	}
	cout << output << '\n';
}

int main() {
    //ios_base::sync_with_stdio(0);
    //cin.tie(0); cout.tie(0);
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);

    int tc; cin >> tc;
    for (int t = 1; t <= tc; t++) {
        // cout << "Case #" << t  << ": ";
        solve();
    }
}


#include <bits/stdc++.h>

using namespace std;

#define ar array
#define ll long long

const int MAX_N = 1e5 + 1;
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll LINF = 1e18;

void solve() {

	int n;
	cin >> n;
	if(n == 1){
		cout << "0\n";
		return;
	}
	vector<int> candy(n), orange(n);
	for(int i{}; i < n; ++i){
		cin >> candy[i];
	}
	for(int i{}; i < n; ++i){
		cin >> orange[i];
	}
	int smallestCandy = *min_element(candy.begin(), candy.end());
	int smallestOrange = *min_element(orange.begin(), orange.end());
	ll output{};
	ll cdiff, odiff;
	for(int i{}; i < n; ++i){
		cdiff = candy[i] - smallestCandy;
		odiff = orange[i] - smallestOrange;
		output += min(cdiff, odiff) + abs(cdiff - odiff);
	}
	cout << output << '\n';
}

int main() {
    //ios_base::sync_with_stdio(0);
    //cin.tie(0); cout.tie(0);
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);

    int tc; cin >> tc;
    for (int t = 1; t <= tc; t++) {
        // cout << "Case #" << t  << ": ";
        solve();
    }
}

// #include <bits/stdc++.h>
// using namespace std;
// typedef long long LL;
// int main() {
//     LL T, N;
//     cin >> T;
//     while (T--) {
//         cin >> N;
//         vector<LL> a(N), b(N);
//         for (LL i = 0; i < N; ++i)
//             cin >> a[i];
//         for (LL i = 0; i < N; ++i)
//             cin >> b[i];
//         LL sa = LLONG_MAX;
//         for (LL x : a)
//             sa = min(sa, x);
//         LL sb = LLONG_MAX;
//         for (LL x : b)
//             sb = min(sb, x);
//         LL ans = 0;
//         for (LL i = 0; i < N; ++i) {
//             LL da = a[i] - sa, db = b[i] - sb;
//             LL little = min(da, db);
//             da -= little, db -= little;
//             ans += little + da + db;
//         }
//         cout << ans << '\n';
//     }
// }


#include <bits/stdc++.h>

using namespace std;

#define ar array
#define long long long

const int MAX_N = 1e5 + 1;
const int MOD = 1e9 + 7;
const int INF = 1e9;
const long LINF = 1e18;

void solve() {
	long smallestCandy{LINF}, smallestOrange{LINF}, n;
	cin >> n;
	if(n == 1){
		cout << 0;
		return;
	}
	vector<int> candy, orange;
	for(int i{}; i < n; ++i){
		long temp;
		cin >> temp;
		smallestCandy = min(smallestCandy, temp);
		candy.push_back(temp);
	}
	for(int i{}; i < n; ++i){
		long temp;
		cin >> temp;
		smallestOrange = min(smallestOrange, temp);
		orange.push_back(temp);
	}
	long output{};
	for(int i{}; i < n; ++i){
		long cdiff, odiff;
		cdiff = candy[i] - smallestCandy;
		odiff = orange[i] - smallestOrange;
		output += min(cdiff, odiff) + abs(cdiff - odiff);
	}
	cout << output << '\n';
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);

    int tc; cin >> tc;
    for (int t = 1; t <= tc; t++) {
        // cout << "Case #" << t  << ": ";
        solve();
    }
}


#include <bits/stdc++.h>

using namespace std;

#define ar array
#define long long long

const int MAX_N = 1e5 + 1;
const int MOD = 1e9 + 7;
const int INF = 1e9;
const long LINF = 1e18;

void solve() {
	int smallestCandy{INF}, smallestOrange{INF}, n;
	cin >> n;
	if(n == 1){
		cout << "0\n";
		return;
	}
	int temp;
	vector<int> candy, orange;
	for(int i{}; i < n; ++i){
		cin >> temp;
		smallestCandy = min(smallestCandy, temp);
		candy.push_back(temp);
	}
	for(int i{}; i < n; ++i){

		cin >> temp;
		smallestOrange = min(smallestOrange, temp);
		orange.push_back(temp);
	}
	long output{};
	int cdiff, odiff;
	for(int i{}; i < n; ++i){
		cdiff = candy[i] - smallestCandy;
		odiff = orange[i] - smallestOrange;
		output += min(cdiff, odiff) + abs(cdiff - odiff);
	}
	cout << output << '\n';
}

int main() {
    // ios_base::sync_with_stdio(0);
    // cin.tie(0); cout.tie(0);
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);

    int tc; cin >> tc;
    for (int t = 1; t <= tc; t++) {
        // cout << "Case #" << t  << ": ";
        solve();
    }
}


#include <bits/stdc++.h>

using namespace std;

#define ar array
#define ll long long

const int MAX_N = 1e5 + 1;
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll LINF = 1e18;

void solve() {

	int n;
	cin >> n;
	if(n == 1){
		cout << "0\n";
		return;
	}
	vector<int> candy(n), orange(n);
	for(int i{}; i < n; ++i){
		cin >> candy[i];
	}
	for(int i{}; i < n; ++i){
		cin >> orange[i];
	}
	int smallestCandy = *min_element(candy.begin(), candy.end());
	int smallestOrange = *min_element(orange.begin(), orange.end());
	ll output{};
	for(int i{}; i < n; ++i){
		ll cdiff = candy[i] - smallestCandy;
		ll odiff = orange[i] - smallestOrange;
		output += min(cdiff, odiff) + abs(cdiff - odiff);
	}
	cout << output << '\n';
}

int main() {
    //ios_base::sync_with_stdio(0);
    //cin.tie(0); cout.tie(0);
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);

    int tc; cin >> tc;
    for (int t = 1; t <= tc; t++) {
        // cout << "Case #" << t  << ": ";
        solve();
    }
}

// #include <bits/stdc++.h>
// using namespace std;
// typedef long long LL;
// int main() {
//     LL T, N;
//     cin >> T;
//     while (T--) {
//         cin >> N;
//         vector<LL> a(N), b(N);
//         for (LL i = 0; i < N; ++i)
//             cin >> a[i];
//         for (LL i = 0; i < N; ++i)
//             cin >> b[i];
//         LL sa = LLONG_MAX;
//         for (LL x : a)
//             sa = min(sa, x);
//         LL sb = LLONG_MAX;
//         for (LL x : b)
//             sb = min(sb, x);
//         LL ans = 0;
//         for (LL i = 0; i < N; ++i) {
//             LL da = a[i] - sa, db = b[i] - sb;
//             LL little = min(da, db);
//             da -= little, db -= little;
//             ans += little + da + db;
//         }
//         cout << ans << '\n';
//     }
// }


#include <bits/stdc++.h>

using namespace std;

#define ar array
#define ll long long

const int MAX_N = 1e5 + 1;
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll LINF = 1e18;

void solve() {
	int smallestCandy = INF;
	int smallestOrange = INF;
	int n;
	cin >> n;
	if(n == 1){
		cout << "0\n";
		return;
	}
	int temp;
	vector<int> candy{}, orange{};
	for(int i{}; i < n; ++i){
		cin >> temp;
		smallestCandy = min(smallestCandy, temp);
		candy.push_back(temp);
	}
	for(int i{}; i < n; ++i){
		cin >> temp;
		smallestOrange = min(smallestOrange, temp);
		orange.push_back(temp);
	}
	ll output{};
	ll cdiff, odiff;
	for(int i{}; i < n; ++i){
		cdiff = candy[i] - smallestCandy;
		odiff = orange[i] - smallestOrange;
		output += min(cdiff, odiff) + abs(cdiff - odiff);
	}
	cout << output << '\n';
}

int main() {
    //ios_base::sync_with_stdio(0);
    //cin.tie(0); cout.tie(0);
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);

    int tc; cin >> tc;
    for (int t = 1; t <= tc; t++) {
        // cout << "Case #" << t  << ": ";
        solve();
    }
}


#include <bits/stdc++.h>

using namespace std;

#define ar array
#define ll long long

const int MAX_N = 1e5 + 1;
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll LINF = 1e18;

void solve() {
	ll smallestCandy{LINF}, smallestOrange{LINF}, n;
	cin >> n;
	if(n == 1){
		cout << 0;
		return;
	}
	vector<int> candy, orange;
	for(int i{}; i < n; ++i){
		ll temp;
		cin >> temp;
		smallestCandy = min(smallestCandy, temp);
		candy.push_back(temp);
	}
	for(int i{}; i < n; ++i){
		ll temp;
		cin >> temp;
		smallestOrange = min(smallestOrange, temp);
		orange.push_back(temp);
	}
	ll output{};
	for(int i{}; i < n; ++i){
		ll cdiff, odiff;
		cdiff = candy[i] - smallestCandy;
		odiff = orange[i] - smallestOrange;
		cout << cdiff << "  " << odiff << '\n';
		output += min(cdiff, odiff) + abs(cdiff - odiff);
	}
	cout << output << '\n';
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);

    int tc; cin >> tc;
    for (int t = 1; t <= tc; t++) {
        // cout << "Case #" << t  << ": ";
        solve();
    }
}


#include <bits/stdc++.h>

using namespace std;

#define ar array
#define long long long

const int MAX_N = 1e5 + 1;
const int MOD = 1e9 + 7;
const int INF = 1e9;
const long LINF = 1e18;

void solve() {
	int smallestCandy{INF}, smallestOrange{INF}, n;
	cin >> n;
	if(n == 1){
		cout << 0;
		return;
	}
	int temp;
	vector<int> candy, orange;
	for(int i{}; i < n; ++i){
		cin >> temp;
		smallestCandy = min(smallestCandy, temp);
		candy.push_back(temp);
	}
	for(int i{}; i < n; ++i){

		cin >> temp;
		smallestOrange = min(smallestOrange, temp);
		orange.push_back(temp);
	}
	long output{};
	int cdiff, odiff;
	for(int i{}; i < n; ++i){
		cdiff = candy[i] - smallestCandy;
		odiff = orange[i] - smallestOrange;
		output += min(cdiff, odiff) + abs(cdiff - odiff);
	}
	cout << output << '\n';
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);

    int tc; cin >> tc;
    for (int t = 1; t <= tc; t++) {
        // cout << "Case #" << t  << ": ";
        solve();
    }
}


#include <bits/stdc++.h>

using namespace std;

#define ar array
#define long long long

const int MAX_N = 1e5 + 1;
const int MOD = 1e9 + 7;
const int INF = 1e9;
const long LINF = 1e18;

void solve() {
	int smallestCandy{INF}, smallestOrange{INF}, n;
	cin >> n;
	if(n == 1){
		cout << "0\n";
		return;
	}
	int temp;
	vector<int> candy, orange;
	for(int i{}; i < n; ++i){
		cin >> temp;
		smallestCandy = min(smallestCandy, temp);
		candy.push_back(temp);
	}
	for(int i{}; i < n; ++i){
		cin >> temp;
		smallestOrange = min(smallestOrange, temp);
		orange.push_back(temp);
	}
	long output{};
	int cdiff, odiff;
	for(int i{}; i < n; ++i){
		cdiff = candy[i] - smallestCandy;
		odiff = orange[i] - smallestOrange;
		output += min(cdiff, odiff) + abs(cdiff - odiff);
	}
	cout << output << '\n';
	candy.clear();
	orange.clear();
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);

    int tc; cin >> tc;
    for (int t = 1; t <= tc; t++) {
        // cout << "Case #" << t  << ": ";
        solve();
    }
}


#include <bits/stdc++.h>

using namespace std;

#define ar array
#define long long long

const int MAX_N = 1e5 + 1;
const int MOD = 1e9 + 7;
const int INF = 1e9;
const long LINF = 1e18;

void solve() {
	int smallestCandy{INF}, smallestOrange{INF}, n;
	cin >> n;
	if(n == 1){
		cout << 0;
		return;
	}
	vector<int> candy, orange;
	for(int i{}; i < n; ++i){
		int temp;
		cin >> temp;
		smallestCandy = min(smallestCandy, temp);
		candy.push_back(temp);
	}
	for(int i{}; i < n; ++i){
		int temp;
		cin >> temp;
		smallestOrange = min(smallestOrange, temp);
		orange.push_back(temp);
	}
	long output{};
	for(int i{}; i < n; ++i){
		int cdiff, odiff;
		cdiff = candy[i] - smallestCandy;
		odiff = orange[i] - smallestOrange;
		output += min(cdiff, odiff) + abs(cdiff - odiff);
	}
	cout << output << '\n';
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);

    int tc; cin >> tc;
    for (int t = 1; t <= tc; t++) {
        // cout << "Case #" << t  << ": ";
        solve();
    }
}


#include <bits/stdc++.h>

using namespace std;

#define ar array
#define ll long long

const int MAX_N = 1e5 + 1;
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll LINF = 1e18;

void solve() {
	int smallestCandy = INF;
	int smallestOrange = INF;
	int n;
	cin >> n;
	if(n == 1){
		cout << "0\n";
		return;
	}
	vector<int> candy(n), orange(n);
	for(int i{}; i < n; ++i){
		cin >> candy[i];
		smallestCandy = min(smallestCandy, candy[i]);
	}
	for(int i{}; i < n; ++i){
		cin >> orange[i];
		smallestOrange = min(smallestOrange, orange[i]);
	}
	ll output{};
	ll cdiff, odiff;
	for(int i{}; i < n; ++i){
		cdiff = candy[i] - smallestCandy;
		odiff = orange[i] - smallestOrange;
		output += min(cdiff, odiff) + abs(cdiff - odiff);
	}
	cout << output << '\n';
}

int main() {
    //ios_base::sync_with_stdio(0);
    //cin.tie(0); cout.tie(0);
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);

    int tc; cin >> tc;
    for (int t = 1; t <= tc; t++) {
        // cout << "Case #" << t  << ": ";
        solve();
    }
}

// #include <bits/stdc++.h>
// using namespace std;
// typedef long long LL;
// int main() {
//     LL T, N;
//     cin >> T;
//     while (T--) {
//         cin >> N;
//         vector<LL> a(N), b(N);
//         for (LL i = 0; i < N; ++i)
//             cin >> a[i];
//         for (LL i = 0; i < N; ++i)
//             cin >> b[i];
//         LL sa = LLONG_MAX;
//         for (LL x : a)
//             sa = min(sa, x);
//         LL sb = LLONG_MAX;
//         for (LL x : b)
//             sb = min(sb, x);
//         LL ans = 0;
//         for (LL i = 0; i < N; ++i) {
//             LL da = a[i] - sa, db = b[i] - sb;
//             LL little = min(da, db);
//             da -= little, db -= little;
//             ans += little + da + db;
//         }
//         cout << ans << '\n';
//     }
// }


#include <bits/stdc++.h>

using namespace std;

#define ar array
#define ll long long

const int MAX_N = 1e5 + 1;
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll LINF = 1e18;

void solve() {
	int smallestCandy = INF;
	int smallestOrange = INF;
	int n;
	cin >> n;
	if(n == 1){
		cout << "0\n";
		return;
	}
	int temp;
	vector<int> candy, orange;
	for(int i{}; i < n; ++i){
		cin >> temp;
		smallestCandy = min(smallestCandy, temp);
		candy.push_back(temp);
	}
	for(int i{}; i < n; ++i){
		cin >> temp;
		smallestOrange = min(smallestOrange, temp);
		orange.push_back(temp);
	}
	ll output{};
	int cdiff, odiff;
	for(int i{}; i < n; ++i){
		cdiff = candy[i] - smallestCandy;
		odiff = orange[i] - smallestOrange;
		output += min(cdiff, odiff) + abs(cdiff - odiff);
	}
	cout << output << '\n';
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);

    int tc; cin >> tc;
    for (int t = 1; t <= tc; t++) {
        // cout << "Case #" << t  << ": ";
        solve();
    }
}


// #include <bits/stdc++.h>

// using namespace std;

// #define ar array
// #define ll long long

// const int MAX_N = 1e5 + 1;
// const int MOD = 1e9 + 7;
// const int INF = 1e9;
// const ll LINF = 1e18;

// void solve() {
// 	int smallestCandy = INF;
// 	int smallestOrange = INF;
// 	int n;
// 	cin >> n;
// 	if(n == 1){
// 		cout << "0\n";
// 		return;
// 	}
// 	int temp;
// 	vector<int> candy(n), orange(n);
// 	for(int i{}; i < n; ++i){
// 		cin >> temp;
// 		smallestCandy = min(smallestCandy, temp);
// 		candy[i] = (temp);
// 	}
// 	for(int i{}; i < n; ++i){
// 		cin >> temp;
// 		smallestOrange = min(smallestOrange, temp);
// 		orange[i] = (temp);
// 	}
// 	ll output{};
// 	ll cdiff, odiff;
// 	for(int i{}; i < n; ++i){
// 		cdiff = candy[i] - smallestCandy;
// 		odiff = orange[i] - smallestOrange;
// 		output += min(cdiff, odiff) + abs(cdiff - odiff);
// 	}
// 	cout << output << '\n';
// }

// int main() {
//     //ios_base::sync_with_stdio(0);
//     //cin.tie(0); cout.tie(0);
//     // freopen("input.txt", "r", stdin);
//     // freopen("output.txt", "w", stdout);

//     int tc; cin >> tc;
//     for (int t = 1; t <= tc; t++) {
//         // cout << "Case #" << t  << ": ";
//         solve();
//     }
// }

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
int main() {
    LL T, N;
    cin >> T;
    while (T--) {
        cin >> N;
        vector<LL> a(N), b(N);
        for (LL i = 0; i < N; ++i)
            cin >> a[i];
        for (LL i = 0; i < N; ++i)
            cin >> b[i];
        LL sa = LLONG_MAX;
        for (LL x : a)
            sa = min(sa, x);
        LL sb = LLONG_MAX;
        for (LL x : b)
            sb = min(sb, x);
        LL ans = 0;
        for (LL i = 0; i < N; ++i) {
            LL da = a[i] - sa, db = b[i] - sb;
            LL little = min(da, db);
            da -= little, db -= little;
            ans += little + da + db;
        }
        cout << ans << '\n';
    }
}


#include<bits/stdc++.h>
using namespace std;
#define REP(i,n) for (int i = 0; i <n; i++)
#define mod 1000000007
#define pb push_back
#define ff first
#define ss second
#define ii pair<int,int>
#define vi vector<int>
#define vii vector<ii>
#define pq priority_queue<int>
#define lli long long int
#define INF 1000000000
#define endl '\n'

#define fr(i,s,n) for(int i =s;i<n;i++)
#define  fre(i,s,n) for(int i =s;i<=n;i++)

int main()
{
    ios_base::sync_with_stdio(0) ;
	cin.tie(0);
    int t;
    cin>>t;
    while(t--)
     {
         long long int temp,min1,min2,ans=0;
         min1 = INF;
         min2 = INF;
         int n;
         cin>>n;
         long long int vect1[n],vect2[n];
        REP(i,n)
        {
            cin>>vect1[i];

            min1  = min(min1,vect1[i]);
        }
        REP(i,n)
        {
           cin>>vect2[i];

            min2  = min(min2,vect2[i]);
        }
        REP(i,n)
         {
             ans = ans + max(vect1[i]-min1,vect2[i]-min2);
         };

         cout<<ans<<endl;
     }
     return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define REP(i,n) for (int i = 0; i <n; i++)
#define mod 1000000007
#define pb push_back
#define ff first
#define ss second
#define ii pair<int,int>
#define vi vector<int>
#define vii vector<ii>
#define pq priority_queue<int>
#define lli long long int
#define INF 1000000000
#define endl '\n'

#define fr(i,s,n) for(int i =s;i<n;i++)
#define  fre(i,s,n) for(int i =s;i<=n;i++)

int main()
{
    ios_base::sync_with_stdio(0) ;
	cin.tie(0);
    int t;
    cin>>t;
    while(t--)
     {
         long long int temp,min1,min2,ans=0;
         min1 = INF;
         min2 = INF;
         int n;
         cin>>n;
         long long int vect1[n],vect2[n];
        REP(i,n)
        {
            cin>>vect1[i];

            min1  = min(min1,vect1[i]);
        }
        REP(i,n)
        {
           cin>>vect2[i];

            min2  = min(min2,vect2[i]);
        }

        REP(i,n)
         {
             ans = ans + max(vect1[i]-min1,vect2[i]-min2);
         };
         cout<<ans<<endl;
     }
     return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define REP(i,n) for (int i = 0; i <n; i++)
#define mod 1000000007
#define pb push_back
#define ff first
#define ss second
#define ii pair<int,int>
#define vi vector<int>
#define vii vector<ii>
#define pq priority_queue<int>
#define lli long long int
#define INF 1000000000
#define endl '\n'

#define fr(i,s,n) for(int i =s;i<n;i++)
#define  fre(i,s,n) for(int i =s;i<=n;i++)

int main()
{
    ios_base::sync_with_stdio(0) ;
	cin.tie(0);
    int t;
    cin>>t;
    while(t--)
     {
         long long int temp,min1,min2,ans=0;
         min1 = INF;
         min2 = INF;
         int n;
         cin>>n;
         long long int vect1[n],vect2[n];
        REP(i,n)
        {
            cin>>vect1[i];

            min1  = min(min1,vect1[i]);
        }
        REP(i,n)
        {
           cin>>vect2[i];

            min2  = min(min2,vect2[i]);
        }

        REP(i,n)
         {
             ans = ans + max(vect1[i]-min1,vect2[i]-min2);
         };
         cout<<ans<<“\n”;
     }
     return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define REP(i,n) for (int i = 0; i <n; i++)
#define mod 1000000007
#define pb push_back
#define ff first
#define ss second
#define ii pair<int,int>
#define vi vector<int>
#define vii vector<ii>
#define pq priority_queue<int>
#define lli long long int
#define INF 1000000000
#define endl '\n'

#define fr(i,s,n) for(int i =s;i<n;i++)
#define  fre(i,s,n) for(int i =s;i<=n;i++)

int main()
{
    int t;
    cin>>t;
    while(t--)
     {
         long long int temp,min1,min2,ans=0;
         min1 = INF;
         min2 = INF;
         int n;
         cin>>n;
        vector <long long int > vect1;
        vector <long long int > vect2;
        REP(i,n)
        {
            cin>>temp;
            vect1.push_back(temp);
            min1  = min(min1,temp);
        }
        REP(i,n)
        {
            cin>>temp;
            vect2.push_back(temp);
            min2  = min(min2,temp);
        }

        REP(i,n)
         {
             ans = ans + max(vect1[i]-min1,vect2[i]-min2);
         };
         cout<<ans<<endl;
     }
     return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define REP(i,n) for (int i = 0; i <n; i++)
#define mod 1000000007
#define pb push_back
#define ff first
#define ss second
#define ii pair<int,int>
#define vi vector<int>
#define vii vector<ii>
#define pq priority_queue<int>
#define lli long long int
#define INF 1000000000
#define endl '\n'

#define fr(i,s,n) for(int i =s;i<n;i++)
#define  fre(i,s,n) for(int i =s;i<=n;i++)

int main()
{
    int t;
    cin>>t;
    while(t--)
     {
         long long int temp,min1,min2,ans=0;
         min1 = INF;
         min2 = INF;
         int n;
         cin>>n;
         long long int vect1[n],vect2[n];
        REP(i,n)
        {
            cin>>vect1[i];

            min1  = min(min1,vect1[i]);
        }
        REP(i,n)
        {
           cin>>vect2[i];

            min2  = min(min2,vect2[i]);
        }

        REP(i,n)
         {
             ans = ans + max(vect1[i]-min1,vect2[i]-min2);
         };
         cout<<ans<<endl;
     }
     return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define REP(i,n) for (int i = 0; i <n; i++)
#define mod 1000000007
#define pb push_back
#define ff first
#define ss second
#define ii pair<int,int>
#define vi vector<int>
#define vii vector<ii>
#define pq priority_queue<int>
#define lli long long int
#define INF 1000000000
#define endl '\n'

#define fr(i,s,n) for(int i =s;i<n;i++)
#define  fre(i,s,n) for(int i =s;i<=n;i++)

int main()
{
    ios_base::sync_with_stdio(0) ;
	cin.tie(0);
    cout.tie(0);
        #ifndef ONLINE_JUDGE
        freopen("fin.txt", "r", stdin);
        freopen("fout.txt", "w", stdout);
    #endif
    int t;
    cin>>t;
    while(t--)
     {
         long long int temp,min1,min2,ans=0;
         min1 = INF;
         min2 = INF;
         int n;
         cin>>n;
         long long int vect1[n],vect2[n];
        REP(i,n)
        {
            cin>>vect1[i];

            min1  = min(min1,vect1[i]);
        }
        REP(i,n)
        {
           cin>>vect2[i];

            min2  = min(min2,vect2[i]);
        }

        REP(i,n)
         {
             ans = ans + max(vect1[i]-min1,vect2[i]-min2);
         };
         cout<<ans<<endl;
     }
     return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define REP(i,n) for (int i = 0; i <n; i++)
#define mod 1000000007
#define pb push_back
#define ff first
#define ss second
#define ii pair<int,int>
#define vi vector<int>
#define vii vector<ii>
#define pq priority_queue<int>
#define lli long long int
#define INF 1000000000
#define endl '\n'

#define fr(i,s,n) for(int i =s;i<n;i++)
#define  fre(i,s,n) for(int i =s;i<=n;i++)

long long int temp,min1,min2,ans=0;
int main()
{
    int t;
    cin>>t;
    while(t--)
     {

         min1 = INF;
         min2 = INF;
         int n;
         cin>>n;
         long long int vect1[n],vect2[n];
        REP(i,n)
        {
            cin>>vect1[i];

        }
        REP(i,n)
        {
           cin>>vect2[i];

        }
        		 min1 = *min_element(vect1 , vect1 + n) ;
		 min2 = *min_element(vect2 , vect2 + n) ;

        REP(i,n)
         {
             ans = ans + max(vect1[i]-min1,vect2[i]-min2);
         };
         cout<<ans<<endl;
     }
     return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define REP(i,n) for (int i = 0; i <n; i++)
#define mod 1000000007
#define pb push_back
#define ff first
#define ss second
#define ii pair<int,int>
#define vi vector<int>
#define vii vector<ii>
#define pq priority_queue<int>
#define lli long long int
#define INF 1000000000
#define endl '\n'

#define fr(i,s,n) for(int i =s;i<n;i++)
#define  fre(i,s,n) for(int i =s;i<=n;i++)

int main()
{
    int t;
    cin>>t;
    while(t--)
     {
         long long int temp;
         int n;
         cin>>n;
        vector <long long int > vect1;
        vector <long long int > vect2;

        REP(i,n)
        {
            cin>>temp;
            vect1.push_back(temp);
        }
        REP(i,n)
        {
            cin>>temp;
            vect2.push_back(temp);
        }

        long long int min1 = *min_element(vect1.begin(), vect1.end());
        long long int min2 = *min_element(vect2.begin(), vect2.end());
        long long int ans =0;

        REP(i,n)
         {
             ans = ans + max(vect1[i]-min1,vect2[i]-min2);
         };
         cout<<ans<<endl;
     }
     return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define REP(i,n) for (int i = 0; i <n; i++)
#define mod 1000000007
#define pb push_back
#define ff first
#define ss second
#define ii pair<int,int>
#define vi vector<int>
#define vii vector<ii>
#define pq priority_queue<int>
#define lli long long int
#define INF 1000000000
#define endl '\n'

#define fr(i,s,n) for(int i =s;i<n;i++)
#define  fre(i,s,n) for(int i =s;i<=n;i++)

int main()
{
    ios_base::sync_with_stdio(0) ;
	cin.tie(0);
    int t;
    cin>>t;
    while(t--)
     {
         long long int temp,min1,min2,ans=0;
         min1 = INF;
         min2 = INF;
         int n;
         cin>>n;
         long long int vect1[n],vect2[n];
        REP(i,n)
        {
            cin>>vect1[i];

            min1  = min(min1,vect1[i]);
        }
        REP(i,n)
        {
           cin>>vect2[i];

            min2  = min(min2,vect2[i]);
        }

        REP(i,n)
         {
             ans = ans + max(vect1[i]-min1,vect2[i]-min2);
         };
         cout<<ans<<"\n";
     }
     return 0;
}


#include<bits/stdc++.h>
#include<limits.h>
using namespace std;

#define debug(x) cout<< (#x) <<" = "<< (x) << endl

int main()
{
    int t, ind = 0;
    cin >> t;
    long long int out[t];
    while(t--)
    {
        int n;
        cin >> n;
        vector<long long int> a;
        vector<long long int> b;

        a.reserve(n);
        b.reserve(n);

        int min_a, min_b;
        for(int i=0; i<n; i++) {
            cin>>a[i];
            if(i==0) min_a = a[0];
            if(a[i] < min_a)
                min_a = a[i];
        }

        for(int i=0; i<n; i++) {
            cin>>b[i];
            if(i==0) min_b = b[0];
            if(b[i] < min_b)
                min_b = b[i];
        }

        long long int n_steps = 0;
        for(int i=0; i<n; i++) {
            int min_min_ab = min(a[i] - min_a, b[i] - min_b);

            n_steps += min_min_ab;

            if(min_min_ab == a[i]-min_a)
                n_steps += (b[i] - min_b - min_min_ab);
            else
                n_steps += (a[i] - min_a - min_min_ab);
        }

        out[ind++] = n_steps;
    }

    for(int i=0; i<ind; i++)
        cout << out[i] << "\n";
}


#include<bits/stdc++.h>
#include<limits.h>
using namespace std;

#define debug(x) cout<< (#x) <<" = "<< (x) << endl

int main()
{
    int t;
    cin >> t;
    while(t--)
    {
        int n;
        cin >> n;
        vector<int> a;
        vector<int> b;

        a.reserve(n);
        b.reserve(n);

        int min_a = INT_MAX, min_b = INT_MAX;
        for(int i=0; i<n; i++) {
            cin>>a[i];
            if(a[i] < min_a)
                min_a = a[i];
        }

        for(int i=0; i<n; i++) {
            cin>>b[i];
            if(b[i] < min_b)
                min_b = b[i];
        }

        int n_steps = 0;
        for(int i=0; i<n; i++) {
            int min_min_ab = min(a[i] - min_a, b[i] - min_b);

            n_steps += min_min_ab;

            if(min_min_ab == a[i]-min_a)
                n_steps += (b[i] - min_b - min_min_ab);
            else
                n_steps += (a[i] - min_a - min_min_ab);
        }

        cout<<n_steps<<"\n";
    }
}


#include<bits/stdc++.h>
#include<limits.h>
using namespace std;

#define debug(x) cout<< (#x) <<" = "<< (x) << endl

int main()
{
    int t, ind = 0;
    cin >> t;
    long out[t];
    while(t--)
    {
        int n;
        cin >> n;
        vector<long> a;
        vector<long> b;

        a.reserve(n);
        b.reserve(n);

        int min_a, min_b;
        for(int i=0; i<n; i++) {
            cin>>a[i];
            if(i==0) min_a = a[0];
            if(a[i] < min_a)
                min_a = a[i];
        }

        for(int i=0; i<n; i++) {
            cin>>b[i];
            if(i==0) min_b = b[0];
            if(b[i] < min_b)
                min_b = b[i];
        }

        long n_steps = 0;
        for(int i=0; i<n; i++) {
            int min_min_ab = min(a[i] - min_a, b[i] - min_b);

            n_steps += min_min_ab;

            if(min_min_ab == a[i]-min_a)
                n_steps += (b[i] - min_b - min_min_ab);
            else
                n_steps += (a[i] - min_a - min_min_ab);
        }

        out[ind++] = n_steps;
    }

    for(int i=0; i<ind; i++)
        cout << out[i] << "\n";
}


#include<bits/stdc++.h>
#include<limits.h>
using namespace std;

#define debug(x) cout<< (#x) <<" = "<< (x) << endl

int main()
{
    int t, ind = 0;
    cin >> t;
    int out[t];
    while(t--)
    {
        int n;
        cin >> n;
        vector<unsigned int> a;
        vector<unsigned int> b;

        a.reserve(n);
        b.reserve(n);

        int min_a, min_b;
        for(int i=0; i<n; i++) {
            cin>>a[i];
            if(i==0) min_a = a[0];
            if(a[i] < min_a)
                min_a = a[i];
        }

        for(int i=0; i<n; i++) {
            cin>>b[i];
            if(i==0) min_b = b[0];
            if(b[i] < min_b)
                min_b = b[i];
        }

        int n_steps = 0;
        for(int i=0; i<n; i++) {
            int min_min_ab = min(a[i] - min_a, b[i] - min_b);

            n_steps += min_min_ab;

            if(min_min_ab == a[i]-min_a)
                n_steps += (b[i] - min_b - min_min_ab);
            else
                n_steps += (a[i] - min_a - min_min_ab);
        }

        out[ind++] = n_steps;
    }

    for(int i=0; i<ind; i++)
        cout << out[i] << "\n";
}


#include<bits/stdc++.h>
#include<limits.h>
using namespace std;

#define debug(x) cout<< (#x) <<" = "<< (x) << endl

int main()
{
    int t, ind = 0;
    cin >> t;
    int out[t];
    while(t--)
    {
        int n;
        cin >> n;
        vector<int> a;
        vector<int> b;

        a.reserve(n);
        b.reserve(n);

        int min_a = INT_MAX, min_b = INT_MAX;
        for(int i=0; i<n; i++) {
            cin>>a[i];
            if(a[i] < min_a)
                min_a = a[i];
        }

        for(int i=0; i<n; i++) {
            cin>>b[i];
            if(b[i] < min_b)
                min_b = b[i];
        }

        int n_steps = 0;
        for(int i=0; i<n; i++) {
            int min_min_ab = min(a[i] - min_a, b[i] - min_b);

            n_steps += min_min_ab;

            if(min_min_ab == a[i]-min_a)
                n_steps += (b[i] - min_b - min_min_ab);
            else
                n_steps += (a[i] - min_a - min_min_ab);
        }

        out[ind++] = n_steps;
    }

    for(int i=0; i<ind; i++)
        cout << out[i] << "\n";
}


#include<bits/stdc++.h>
#include<limits.h>
using namespace std;

#define debug(x) cout<< (#x) <<" = "<< (x) << endl

int main()
{
    int t, ind = 0;
    cin >> t;
    int out[t];
    while(t--)
    {
        int n;
        cin >> n;
        vector<long> a;
        vector<long> b;

        a.reserve(n);
        b.reserve(n);

        int min_a = LONG_MAX, min_b = LONG_MAX;
        for(int i=0; i<n; i++) {
            cin>>a[i];
            if(a[i] < min_a)
                min_a = a[i];
        }

        for(int i=0; i<n; i++) {
            cin>>b[i];
            if(b[i] < min_b)
                min_b = b[i];
        }

        int n_steps = 0;
        for(int i=0; i<n; i++) {
            int min_min_ab = min(a[i] - min_a, b[i] - min_b);

            n_steps += min_min_ab;

            if(min_min_ab == a[i]-min_a)
                n_steps += (b[i] - min_b - min_min_ab);
            else
                n_steps += (a[i] - min_a - min_min_ab);
        }

        out[ind++] = n_steps;
    }

    for(int i=0; i<ind; i++)
        cout << out[i] << "\n";
}


#include<bits/stdc++.h>
#include<limits.h>
using namespace std;

using long long = ll
#define debug(x) cout<< (#x) <<" = "<< (x) << endl

int main()
{
    int t, ind = 0;
    cin >> t;
    ll out[t];
    while(t--)
    {
        int n;
        cin >> n;
        vector<ll> a;
        vector<ll> b;

        a.reserve(n);
        b.reserve(n);

        int min_a, min_b;
        for(int i=0; i<n; i++) {
            cin>>a[i];
            if(i==0) min_a = a[0];
            if(a[i] < min_a)
                min_a = a[i];
        }

        for(int i=0; i<n; i++) {
            cin>>b[i];
            if(i==0) min_b = b[0];
            if(b[i] < min_b)
                min_b = b[i];
        }

        ll n_steps = 0;
        for(int i=0; i<n; i++) {
            int min_min_ab = min(a[i] - min_a, b[i] - min_b);

            n_steps += min_min_ab;

            if(min_min_ab == a[i]-min_a)
                n_steps += (b[i] - min_b - min_min_ab);
            else
                n_steps += (a[i] - min_a - min_min_ab);
        }

        out[ind++] = n_steps;
    }

    for(int i=0; i<ind; i++)
        cout << out[i] << "\n";
}


#include<bits/stdc++.h>
#include<limits.h>
using namespace std;

#define debug(x) cout<< (#x) <<" = "<< (x) << endl

int main()
{
    int t, ind = 0;
    cin >> t;
    long out[t];
    while(t--)
    {
        int n;
        cin >> n;
        vector<unsigned int> a;
        vector<unsigned int> b;

        a.reserve(n);
        b.reserve(n);

        int min_a, min_b;
        for(int i=0; i<n; i++) {
            cin>>a[i];
            if(i==0) min_a = a[0];
            if(a[i] < min_a)
                min_a = a[i];
        }

        for(int i=0; i<n; i++) {
            cin>>b[i];
            if(i==0) min_b = b[0];
            if(b[i] < min_b)
                min_b = b[i];
        }

        long n_steps = 0;
        for(int i=0; i<n; i++) {
            int min_min_ab = min(a[i] - min_a, b[i] - min_b);

            n_steps += min_min_ab;

            if(min_min_ab == a[i]-min_a)
                n_steps += (b[i] - min_b - min_min_ab);
            else
                n_steps += (a[i] - min_a - min_min_ab);
        }

        out[ind++] = n_steps;
    }

    for(int i=0; i<ind; i++)
        cout << out[i] << "\n";
}


#include<bits/stdc++.h>
using namespace std;

int main(){

    int t;

    cin>>t;

    while(t--){

    int n;

    cin>>n;
    int a[n],b[n];
    int m1=10000000,m2=10000000;
    for(int i=0;i<n;i++){
        cin>>a[i];
        m1=min(m1,a[i]);

    }
       for(int i=0;i<n;i++){
        cin>>b[i];
        m2=min(m2,b[i]);
    }

    long long s1,s2,s3,s=0;

    for(int i=0;i<n;i++){

             s1=a[i]-m1;
             s2=b[i]-m2;
             s3=max(s1,s2);
             s+=s3;

       // cout<<s1<<" "<<s2<<" "<<s3<<endl;
        //cout<<s<<endl;

    }

     cout<<s<<endl;

    }

    }


#include<bits/stdc++.h>
using namespace std;

int main(){

    int t;

    cin>>t;

    while(t--){

    int n;

    cin>>n;
    int a[n],b[n];
    int m1=10000000,m2=10000000;
    for(int i=0;i<n;i++){
        cin>>a[i];
        m1=min(m1,a[i]);

    }
       for(int i=0;i<n;i++){
        cin>>b[i];
        m2=min(m2,b[i]);
    }

    long long s1,s2,s3,s=0;

    for(int i=0;i<n;i++){

             s1=a[i]-m1;
             s2=b[i]-m2;
             s3=max(s1,s2);
             s+=s3;

       // cout<<s1<<" "<<s2<<" "<<s3<<endl;
        //cout<<s<<endl;

    }

    }

    cout<<s<<endl;

    }

}


#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        long long int i,j;
        long long int a[n],b[n];
         long long int min1=INT_MAX,min2=INT_MAX;
        for(i=0;i<n;i++)
        {
            cin>>a[i];
            min1=min(min1,a[i]);
        }
        for(i=0;i<n;i++)
        {
            cin>>b[i];
            min2=min(min2,b[i]);
        }
        long long int ans=0,val1=0,val2=0;
        for(j=0;j<n;j++)
        {
        val1=a[j]-min1;
        val2=b[j]-min2;
        if(val1>val2)
        {
            ans=ans+val1;
        }
        else
        {
            ans=ans+val2;
        }

        }
        cout<<ans<<endl;

    }
}


#include<iostream>
#include<climits>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n,max2=INT_MAX,max1=INT_MAX;
        int i,j;
        int a[n],b[n];
        for(i=0;i<n;i++)
        {
            cin>>a[i];
            if(a[i]<max2)
            {
                max2=a[i];
            }
    }
        for(i=0;i<n;i++)
        {
            cin>>a[i];
            if(a[i]<max1)
            {
                max1=a[i];
            }
    }
    int ans=0;
    for(i=0;i<n;i++)
    {
       ans=ans+max(a[i]-max2,b[i]-max1);
    }
    cout<<ans<<endl;
}
}


#include<iostream>
#include<climits>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n,max=INT_MAX,max1=INT_MAX;
        int i,j;
        int a[n],b[n];
        for(i=0;i<n;i++)
        {
            cin>>a[i];
            if(a[i]<max)
            {
                max=a[i];
            }
    }
        for(i=0;i<n;i++)
        {
            cin>>a[i];
            if(a[i]<max1)
            {
                max1=a[i];
            }
    }
    int ans=0;
    for(i=0;i<n;i++)
    {
       ans=ans+max(a[i]-max,b[i]-max1);
    }
    cout<<ans<<endl;
}
}


#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        long long int i,j;
        long long int a[n],b[n];
         long long int min1=INT_MAX,min2=INT_MAX;
        for(i=0;i<n;i++)
        {
            cin>>a[i];
            min1=min(min1,a[i]);
        }
        for(i=0;i<n;i++)
        {
            cin>>b[i];
            min2=min(min2,b[i]);
        }
        int ans=0,val1,val2;
        for(j=0;j<n;j++)
        {
        ans=ans+max(a[i]-min1,b[i]-min2);
        }
              cout<<ans<<endl;

    }
}


#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        long long int i,j;
        long long int a[n],b[n];
         long long int min1=INT_MAX,min2=INT_MAX;
        for(i=0;i<n;i++)
        {
            cin>>a[i];
            min1=min(min1,a[i]);
        }
        for(i=0;i<n;i++)
        {
            cin>>b[i];
            min2=min(min2,b[i]);
        }
        int ans=0,val1,val2;
        for(j=0;j<n;j++)
        {
        val1=a[i]-min1;
        val2=b[i]-min2;
        if(val1>val2)
        {
            ans=ans+val1;
        }
        else
        {
            ans=ans+val2;
        }

        }
        cout<<ans<<endl;

    }
}


#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        long long int i,j;
        long long int a[n],b[n];
         long long int min1=INT_MAX,min2=INT_MAX;
        for(i=0;i<n;i++)
        {
            cin>>a[i];
            min1=min(min1,a[i]);
        }
        for(i=0;i<n;i++)
        {
            cin>>b[i];
            min2=min(min2,b[i]);
        }
        int ans=0,val1,val2;
        for(j=0;j<n;j++)
        {
        val1=a[j]-min1;
        val2=b[j]-min2;
        if(val1>val2)
        {
            ans=ans+val1;
        }
        else
        {
            ans=ans+val2;
        }

        }
        cout<<ans<<endl;

    }
}


#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        long long int i,j;
        long long int a[n],b[n];
         long long int min1=INT_MAX,min2=INT_MAX;
        for(i=0;i<n;i++)
        {
            cin>>a[i];
            min1=min(min1,a[i]);
        }
        for(i=0;i<n;i++)
        {
            cin>>b[i];
            min2=min(min2,b[i]);
        }
        long long int ans=0,val1=0,val2=0;
        for(j=0;j<n;j++)
        {
        val1=a[i]-min1;
        val2=b[i]-min2;
        if(val1>val2)
        {
            ans=ans+val1;
        }
        else
        {
            ans=ans+val2;
        }

        }
        cout<<ans<<endl;

    }
}


#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        long long int i,j;
        long long int a[n],b[n];
         long long int min1=INT_MAX,min2=INT_MAX;
        for(i=0;i<n;i++)
        {
            cin>>a[i];
            min1=min(min1,a[i]);
        }
        for(i=0;i<n;i++)
        {
            cin>>b[i];
            min2=min(min2,b[i]);
        }
        long long int ans=0,val1,val2;
        for(j=0;j<n;j++)
        {
        ans=ans+max(a[j]-min1,b[j]-min2);
        }
              cout<<ans<<endl;

    }
}


#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        long long int i,j;
        long long int a[n],b[n];
         int min1=INT_MAX,min2=INT_MAX;
        for(i=0;i<n;i++)
        {
            cin>>a[i];
            min1=min(min1,a[i]);
        }
        for(i=0;i<n;i++)
        {
            cin>>b[i];
            min2=min(min2,b[i]);
        }
        int ans=0,val1,val2;
        for(j=0;j<n;j++)
        {
        val1=a[i]-min1;
        val2=b[i]-min2;
        if(val1>val2)
        {
            ans=ans+val1;
        }
        else
        {
            ans=ans+val2;
        }

        }
        cout<<ans<<endl;

    }
}


#include<iostream>
#include<climits>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n,max=INT_MAX,max1=INT_MAX;
        int i,j;
        int a[n],b[n];
        for(i=0;i<n;i++)
        {
            cin>>a[i];
            if(a[i]<max)
            {
                max=a[i];
            }
    }
    .    for(i=0;i<.n;i++)
        {
            cin>>a[i];
            if(a[i]<max1)
            {
                max1=a[i];
            }
    }
    int ans=0;
    for(i=0;i<n;i++)
    {
       ans=ans+max(a[i]-max,.b[i]-max1);
    }
    cout<<ans<<endl;
}
}


#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        long long int i,j;
        long long int a[n],b[n];
         long long int min1=INT_MAX,min2=INT_MAX;
        for(i=0;i<n;i++)
        {
            cin>>a[i];
            min1=min(min1,a[i]);
        }
        for(i=0;i<n;i++)
        {
            cin>>b[i];
            min2=min(min2,b[i]);
        }
        int ans=0,val1,val2;
        for(j=0;j<n;j++)
        {
        ans=ans+max(a[j]-min1,b[j]-min2);
        }
              cout<<ans<<endl;

    }
}


#include<bits/stdc++.h>
const int maxn =  55;
using namespace std;
int t,n;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	cin>>t;
	while(t--)
	{
		cin>>n;
		int a[maxn]={0},b[maxn]={0};
		int minia=1e9+10,minib = 1e9+10;
		for(int i = 1;i <= n; i ++)
		{
			cin>>a[i];
			minia = min(minia,a[i]);
		}
		for(int i = 1;i <= n; i ++)
		{
			cin>>b[i];
			minib = min(minib,b[i]);
		}
		long long ans = 0;
		for(int i = 1;i <= n; i ++)
		{
			ans+=max(a[i]-minia,b[i]-minib);
		}
		cout<<ans<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
const int maxn =  55;
using namespace std;
long long t,n,a[maxn],b[maxn];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	cin>>t;
	while(t--)
	{
		cin>>n;
		memset(a,0,sizeof(a));
		memset(b,0,sizeof(b));
		int minia=1e8,minib = 1e8;
		for(int i = 1;i <= n; i ++)
		{
			cin>>a[i];
			minia = min(minia,a[i]);
		}
		for(int i = 1;i <= n; i ++)
		{
			cin>>b[i];
			minib = min(minib,b[i]);
		}
		long long ans = 0;
		for(int i = 1;i <= n; i ++)
		{
			ans+=max(a[i]-minia,b[i]-minib);
		}
		cout<<ans<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
const int maxn =  55;
using namespace std;
int t,n;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	cin>>t;
	while(t--)
	{
		cin>>n;
		int a[maxn]={0},b[maxn]={0};
		int minia=1<<30,minib = 1<<30;
		for(int i = 1;i <= n; i ++)
		{
			cin>>a[i];
			minia = min(minia,a[i]);
		}
		for(int i = 1;i <= n; i ++)
		{
			cin>>b[i];
			minib = min(minib,b[i]);
		}
		long long ans = 0;
		for(int i = 1;i <= n; i ++)
		{
			ans+=max(a[i]-minia,b[i]-minib);
		}
		cout<<ans<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
const int maxn =  55;
using namespace std;
int t,n,a[maxn],b[maxn];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	cin>>t;
	while(t--)
	{
		cin>>n;
		memset(a,0,sizeof(a));
		memset(b,0,sizeof(b));
		long long minia=1<<28,minib=1<<28;
		for(int i=1;i<=n;i++){
			cin>>a[i];
			minia=min(a[i],minia);
		}
		for(int i=1;i<=n;i++){
			cin>>b[i];
			minib=min(b[i],minib);
		}
		long long ans = 0;
		for(int i=1;i<=n;i++)
		{
			ans+=max(a[i]-minia,b[i]-minib);
		}
		cout<<ans<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
const int maxn =  55;
using namespace std;
int t,n,a[maxn],b[maxn];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	cin>>t;
	while(t--)
	{
		cin>>n;
		memset(a,0,sizeof(a));
		memset(b,0,sizeof(b));
		int minia=0x3fff,minib=0x3fff;
		for(int i=1;i<=n;i++){
			cin>>a[i];
			minia=min(a[i],minia);
		}
		for(int i=1;i<=n;i++){
			cin>>b[i];
			minib=min(b[i],minib);
		}
		long long ans = 0;
		for(int i=1;i<=n;i++)
		{
			ans+=max(a[i]-minia,b[i]-minib);
		}
		cout<<ans<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
const int maxn =  55;
using namespace std;
int t,n,a[maxn],b[maxn];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	cin>>t;
	while(t--)
	{
		cin>>n;
		memset(a,0,sizeof(a));
		memset(b,0,sizeof(b));
		int minia=0x3fff,minib=0x3fff;
		for(int i=1;i<=n;i++){
			cin>>a[i];
			minia=min(a[i],minia);
		}
		for(int i=1;i<=n;i++){
			cin>>b[i];
			minib=min(b[i],minib);
		}
		long long ans = 0;
		for(int i=1;i<=n;i++)
		{
			ans=ans+max(a[i]-minia,b[i]-minib);
		}
		cout<<ans<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
const int maxn =  55;
using namespace std;
int t,n,a[maxn],b[maxn];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	cin>>t;
	while(t--)
	{
		cin>>n;
		memset(a,0,sizeof(a));
		memset(b,0,sizeof(b));
		int aa=1<<28,bb=1<<28;
		for(int i=1;i<=n;i++){
			cin>>a[i];
			aa=min(a[i],aa);
		}
		for(int i=1;i<=n;i++){
			cin>>b[i];
			bb=min(b[i],bb);
		}
		long long ans = 0;
		for(int i=1;i<=n;i++)
		{
			ans+=max(a[i]-aa,b[i]-bb);
		}
		cout<<ans<<endl;
	}
	return 0;
}