#ifndef ONPC
  #define _FORTIFY_SOURCE 0
  #pragma GCC optimize("Ofast")
  #pragma GCC optimize("no-stack-protector")
  #pragma GCC optimize("unroll-loops")
  #pragma GCC target("sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native")
  #pragma GCC optimize("fast-math")
#endif

#include <bits/stdc++.h>

#define mp make_pair
#define eb emplace_back
#define x first
#define y second

template <typename T>
bool chmax(T &a, const T &b) {
    if (a < b) {
      a = b;
        return true;
    }
    return false;
}

template <typename T>
bool chmin(T &a, const T &b) {
    if (a > b) {
      a = b;
      return true;
    }
    return false;
}

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pt;

#ifdef ONPC
mt19937 rnd(228);
#else
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#endif

const ll MOD = 1000000007LL;
const ll MOD2 = 998244353LL;
const ld PI = acos(-1);

#ifdef ONPC
const int MAXN = 100;
#else
const int MAXN = 300100;
#endif
//#define int long long
const ll INF = 1e18;

void solve(){
  int n;
  cin >> n;
  vector<int> p(n);
  for (int i = 1; i < n; i++){
    cin >> p[i];
    p[i]--;
  }
  vector<ll> a(n);
  for (int i = 1; i < n; i++){
    cin >> a[i];
  }
  vector<int> d(n, 0);
  for (int i = 1; i < n; i++){
    if (d[i]) continue;
    vector<int> q;
    int j = i;
    while (j != 0) {
      q.eb(j);
      j = p[j];
    }
    reverse(begin(q), end(q));
    for (int k = 0; k < q.size(); k++){
      d[q[k]] = k + 1;
    }
  }

  vector<vector<int>> v(n, vector<int>());
  for (int i = 0; i < n; i++){
    v[d[i]].eb(i);
  }

  vector<ll> dp(n, 0);
  for (int i = 1; i < n; i++){
    if (v[i].empty()) break;

    ll mnc = INF, mxc = -INF;
    for (int j : v[i]){
      chmin(mnc, a[j]);
      chmax(mxc, a[j]);
    }
    ll mx1 = -INF, mx2 = -INF;
    for (int j : v[i]){
      chmax(mx1, dp[p[j]] + a[j]);
      chmax(mx2, dp[p[j]] - a[j]);
    }
    for (int j : v[i]){
      dp[j] = dp[p[j]] + max(a[j] - mnc, mxc - a[j]);
      chmax(dp[j], mx1 - a[j]);
      chmax(dp[j], mx2 + a[j]);
    }
  }

  ll ans = 0;
  for (int i = 0; i < n; i++) chmax(ans, dp[i]);

  //for (int i = 0; i < n; i++) cerr << i << " : " << dp[i] << '\n';

  cout << ans << '\n';
}

/*
#ifndef ONPC
#define FILEIO
#endif
*/
signed main()
{
    #ifdef FILEIO
      freopen("input.txt", "r", stdin);
      freopen("output.txt", "w", stdout);
    #endif

    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int Q;
    cin >> Q;
    while (Q--)
      solve();

    return 0;
}
