#include <bits/stdc++.h>

const long long INF = 1e18;

void update(long long &x, long long a) { x = std::max(x, a); }

struct Candidates {
  void add(int x, long long y) { v.emplace_back(x, y); }

  void preprocess() {
    std::sort(v.begin(), v.end());
    int size = 1;
    for (int i = 1; i < static_cast<int>(v.size()); ++i) {
      if (v[size - 1].second < v[i].second) {
        v[size++] = v[i];
      }
    }
    v.resize(size);
  }

  long long ask(int x) {
    auto it = std::lower_bound(
        v.begin(), v.end(),
        std::make_pair(x, std::numeric_limits<long long>::max()));
    if (it == v.begin()) {
      return -INF;
    }
    return std::prev(it)->second;
  }

  std::vector<std::pair<int, long long>> v;
};

int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    int n;
    scanf("%d", &n);
    std::vector<std::vector<int>> children(n);
    for (int i = 1, p; i < n; ++i) {
      scanf("%d", &p);
      children[p - 1].push_back(i);
    }
    std::vector<int> value(n);
    for (int i = 1; i < n; ++i) {
      scanf("%d", &value[i]);
    }
    std::vector<int> level{0};
    std::vector<long long> dp(n);
    while (true) {
      std::vector<int> next_level;
      int min_b = INT_MAX, max_b = INT_MIN;
      long long max_neg = -INF, max_pos = -INF;
      for (int r : level) {
        for (int v : children[r]) {
          next_level.push_back(v);
          min_b = std::min(min_b, value[v]);
          max_b = std::max(max_b, value[v]);
          max_neg = std::max(max_neg, dp[r] - value[v]);
          max_pos = std::max(max_pos, dp[r] + value[v]);
        }
      }
      if (next_level.empty()) {
        break;
      }
      for (int r : level) {
        for (int v : children[r]) {
          update(dp[v], dp[r] + std::abs(value[v] - min_b));
          update(dp[v], dp[r] + std::abs(value[v] - max_b));
          update(dp[v], value[v] + max_neg);
          update(dp[v], -value[v] + max_pos);
        }
      }
      level = next_level;
    }
    printf("%lld\n", *std::max_element(dp.begin(), dp.end()));
  }
}