//
//

// red[x] = red[par[x]] + val(x, y)
// red[y] = red[par[x]] + val(x, y)

// red[x] = max(red[par[x]] + val(x, y), red[par[y]] + val(x, y)) 


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

using namespace std;
#define long long long

const int N = 2e5 + 100;

struct FenwickTree {
    long BIT[N];
    int n;

    void reset(int n) {
        this -> n = n;
        for (int i = 1; i <= n; ++i) BIT[i] = -1e18;
    }

    void up(int u, long val) {
        // cerr << "Update at " << u << ' ' << val << '\n';
        for(; u <= n; u += u & -u) BIT[u] = max(BIT[u], val);
    }

    long query(int u) {
        long ans = -1e18;
        // int uu = u;
        for(; u > 0; u -= u & -u) ans = max(ans, BIT[u]);
        // cerr << "Query at " << uu << ' ' << ans << '\n';
        return ans;
    }

}BIT;

vector<int> e[N], vec[N];
int d[N], par[N], a[N];
long red[N];

void dfs(int u, int p) {
    vec[d[u]].push_back(u);
    for (int v : e[u]) if (v != p) {
        par[v] = u;
        d[v] = d[u] + 1;
        dfs(v, u);
    }
}

void Solve() {
    int n;
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        e[i].clear();
        vec[i].clear();
    }
    for (int i = 1; i < n; ++i) {
        int x;
        cin >> x;
        e[i + 1].push_back(x);
        e[x].push_back(i + 1);
    }
    for (int i = 2; i <= n; ++i) cin >> a[i];
    dfs(1, -1);
    red[1] = 0;
    int max_depth = *max_element(d + 1, d + n + 1);
    for (int i = 1; i <= max_depth; ++i) {
        sort(vec[i].begin(), vec[i].end(), [&](int x, int y) {
            return a[x] < a[y];
        });

        for (int x : vec[i]) {
            red[x] = red[par[x]] + max(a[x] - a[vec[i][0]], a[vec[i].back()] - a[x]);
        }
        // for (int v : vec[i]) {
        //     cerr << "1. At d = " << d[v] << ' ' << v << ' ' << red[v] << '\n';
        // }
        BIT.reset(vec[i].size());
        for (int j = 0; j < vec[i].size(); ++j) {
            int x = vec[i][j];
            BIT.up(j + 1, red[par[x]] - a[x]);
            red[x] = max(red[x], BIT.query(j + 1) + a[x]);
        }
        // for (int v : vec[i]) {
        //     cerr << "2. At d = " << d[v] << ' ' << v << ' ' << red[v] << '\n';
        // }
        BIT.reset(vec[i].size());
        reverse(vec[i].begin(), vec[i].end());
        for (int j = 0; j < vec[i].size(); ++j) {
            int x = vec[i][j];
            BIT.up(j + 1, red[par[x]] + a[x]);
            red[x] = max(red[x], BIT.query(j + 1) - a[x]);
        }
        // for (int v : vec[i]) {
        //     cerr << "3. At d = " << d[v] << ' ' << v << ' ' << red[v] << '\n';
        // }
    }
    long ans = -1e18;
    for (int x : vec[max_depth]) {
        ans = max(ans, red[x]);
    }
    cout << ans << '\n';
}
int main() {
    ios::sync_with_stdio(false); cin.tie(NULL);
    int test;
    cin >> test;
    while (test--) Solve();
}