#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;
#define endl '\n'
#define ll long long
#define pi pair<int, int>
#define f first
#define s second

const int mxn = 200000;
int n, k;
ll a[mxn], p[mxn], dp[mxn];
vector<int> g[mxn], v[mxn];

void dfs(int c, int x){
	k = max(k, x);
	v[x].push_back(c);
	for(int i : g[c]) if(i != p[c]) p[i] = c, dfs(i, x + 1);
}

void answer(){
	cin >> n;
	
	for(int i = 0; i < n; i++) dp[i] = 0, g[i].clear(), v[i].clear();
	for(int i = 1; i < n; i++){
		int x;
		cin >> x;
		x--;
		g[x].push_back(i);
		g[i].push_back(x);
	}
	
	for(int i = 1; i < n; i++) cin >> a[i];
	
	k = 0;
	p[0] = -1;
	dfs(0, 0);
	
	for(int i = 1; i <= k; i++){
		sort(v[i].begin(), v[i].end(), [&](int x, int y){ return a[x] < a[y];});
		for(int t = 0; t < 2; t++, reverse(v[i].begin(), v[i].end()))
		for(ll j = 0, l = 0xcfcfcfcfcfcfcfcf; j < v[i].size(); j++){
			int x = v[i][j];
			dp[x] = max({
				dp[x], 
				dp[p[x]] + abs(a[x] - a[v[i][0]]),
				l + (1 - 2 * t) * a[x]
			});
			l = max(l, dp[p[x]] + (2 * t - 1) * a[x]);
		}
	}
	
	ll ret = 0;
	for(int i : v[k]) ret = max(ret, dp[i]);
	
	cout << ret << endl;
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int t;
	cin >> t;
	
	for(int i = 0; i < t; i++) answer();
	
	return 0;
}