#include<bits/stdc++.h>
using namespace std;
#define M 200005
typedef long long ll;

ll ara[M];
ll dp[2][M];
ll baccha[M];

vector<int> vec[M], shob[M];

void dfs(int s, int d = 0)
{
    shob[d].push_back(s);
    for(int v: vec[s]) dfs(v, d+1);
}

bool cmp(int a, int b) { return ara[a] < ara[b]; }

int main()
{
    int t;
    scanf("%d", &t);

    while(t--)
    {
        int n;
        scanf("%d", &n);

        for(int i = 1; i <= n; i++) vec[i].clear();
        for(int i = 0; i <= n; i++) shob[i].clear();

        for(int i = 2; i <= n; i++)
        {
            int u;
            scanf("%d", &u);

            vec[u].push_back(i);
        }

        for(int i = 2; i <= n; i++) scanf("%lld", ara+i);

        dfs(1);

        for(int i = 0; i <= n; i++) sort(shob[i].begin(), shob[i].end(), cmp);

        for(int i = n; i >= 0; i--)
        {
            if(shob[i].empty()) continue;
            int len = shob[i].size();

            vector<ll> preMax(len), sufMax(len);

            for(int s: shob[i])
            {
                baccha[s] = 0;
                for(int v: vec[s]) baccha[s] = max(baccha[s], max(dp[0][v], dp[1][v]));
            }

            for(int j = 0; j < len; j++)
            {
                int s = shob[i][j];

                preMax[j] = baccha[s]-ara[s];
                if(j > 0) preMax[j] = max(preMax[j], preMax[j-1]);
            }

            for(int j = len-1; j >= 0; j--)
            {
                int s = shob[i][j];

                sufMax[j] = baccha[s]+ara[s];
                if(j+1 < len) sufMax[j] = max(sufMax[j], sufMax[j+1]);
            }

            int shuru = shob[i][0], shesh = shob[i][len-1];

            for(int j = 0; j < len; j++)
            {
                int s = shob[i][j];

                dp[0][s] = max(ara[s]-ara[shuru], ara[shesh]-ara[s])+baccha[s];
                dp[1][s] = max(ara[s]+preMax[j], sufMax[j]-ara[s]);
            }
        }

        ll ans = max(dp[0][1], dp[1][1]);
        printf("%lld\n", ans);
    }

    return 0;
}
