#define _CRT_SECURE_NO_WARNINGS
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cassert>
#include <chrono>
#include <random>
#include <bitset>
#include <cstdio>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <ctime>
#include <cmath>
#include <list>
#include <map>
#include <set>

using namespace std;

const int N = 200005;
const int inf = 1000 * 1000 * 1000;
const int mod = 1000 * 1000 * 1000 + 7;
mt19937 myrand(chrono::steady_clock::now().time_since_epoch().count());

int t;
int n, m;
vector <int> g[N];

vector < pair<int, int> > mas[N];
int val[N], mx;
long long dp[N];

void dfs(int v, int r) {
    mx = max(mx, r);
    mas[r].push_back(make_pair(val[v], v));
    for (int i = 0; i < (int)g[v].size(); i++) {
        int to = g[v][i];
        dfs(to, r + 1);
    }
}

void clean() {
    for (int i = 1; i <= n; i++) {
        g[i].clear();
        dp[i] = 0;
    }
    for (int i = 0; i <= mx; i++) {
        mas[i].clear();
    }
    mx = 0;
}

int main() {
    cin >> t;

    while (t--) {
        scanf("%d", &n);
        for (int i = 2; i <= n; i++) {
            int v;
            scanf("%d", &v);
            g[v].push_back(i);
        }

        for (int i = 2; i <= n; i++) {
            scanf("%d", &val[i]);
        }

        dfs(1, 0);

        for (int i = mx; i >= 1; i--) {
            sort(mas[i].begin(), mas[i].end());

            set <long long> Q1;
            for (int j = 0; j < (int)mas[i].size(); j++) {
                int v = mas[i][j].second;
                long long cur = 0;
                for (int h = 0; h < (int)g[v].size(); h++) {
                    int to = g[v][h];
                    cur = max(cur, dp[to]);
                }
                Q1.insert(cur - val[v]);
                set <long long>::iterator it = Q1.end();
                --it;
                dp[v] = max((*it) + val[v], val[v] - mas[i][0].first + cur);
            }

            set <long long> Q2;
            for (int j = (int)mas[i].size() - 1; j >= 0; j--) {
                int v = mas[i][j].second;
                long long cur = 0;
                for (int h = 0; h < (int)g[v].size(); h++) {
                    int to = g[v][h];
                    cur = max(cur, dp[to]);
                }
                Q2.insert(cur + val[v]);
                set <long long>::iterator it = Q2.end();
                --it;
                dp[v] = max(dp[v], (*it) - val[v]);
                dp[v] = max(dp[v], mas[i].back().first - val[v] + cur);
            }
        }

        long long answ = 0;
        for (int i = 0; i < (int)mas[1].size(); i++) {
            int v = mas[1][i].second;
            answ = max(answ, dp[v]);
        }

        printf("%lld\n", answ);

        clean();
    }
    return 0;
}
