#include <bits/stdc++.h>
//#include <bits/extc++.h>
//#define int long long
#define ll long long
#define ull unsigned ll
#define endl "\n"
#define pb push_back
#define ms(v,x) memset(v,x,sizeof(v))
#define ff first
#define ss second
#define td(v) v.begin(),v.end()
#define rep(i,a,n) for (int i=(a);i<(n);i++)
#define per(i,a,n) for (int i=(n-1);i>=a;i--)
#define trav(a, x) for(auto& a : x)
#define re(v) {for(auto &_re : v) cin >> _re;}
#define pr(v) {for(auto _pr : v) cout << _pr << " "; cout << endl;}
#define sz(x) (int)(x).size()
#define all(x) x.begin(), x.end()
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vi vector<int>
#define vl vector<ll>
#define eb emplace_back
using namespace std;
using vvi = vector<vi>;
using vvl = vector<vl>;
//const ll M = 1e9 + 7;
//const ll M = 998244353;
const ll M = 1e9 + 9;
//const ll M = 1e6;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll binpow(ll a, ll b){
	ll res = (a!=0);
	while(b > 0){
		if(b&1) res = res * a % M;
		a = a * a % M;
		b>>=1;
	}
	return res;
}
void solve(){
	int n, d = 0;
	cin >> n;
	vl e(n), a(n), dp(n), lvl[n], lv(n, -1);
	vector<int> adj[n];
	rep(i,1,n){
		cin >> e[i];
		e[i]--;	
		adj[e[i]].eb(i);
	}
	function<void (int)> dfs = [&](int u){
		if(u == 0) lv[u] = -1;
		else lvl[lv[u]].eb(u);
		for(int v : adj[u]){
			lv[v] = lv[u] + 1;
			dfs(v);
		}
		d = max(d, (int)lv[u]);
	};
	dfs(0);
	rep(i,1,n) cin >> a[i];
	for(int i=0;i<=d;i++){
		vector<ll> b(2, -2e18);
		ll mx = a[lvl[i][0]];
		ll mn = mx;
		for(int x : lvl[i]){
			b[0] = max(b[0], dp[e[x]] + a[x]);
			b[1] = max(b[1], dp[e[x]] - a[x]);
			mn = min(mn, a[x]);
			mx = max(mx, a[x]);
		}
		for(int x : lvl[i]){
			dp[x] = dp[e[x]] + max(a[x] - mn, mx - a[x]);
			dp[x] = max(dp[x], b[0] - a[x]);
			dp[x] = max(dp[x], b[1] + a[x]);		
		}
	}
	cout << *max_element(td(dp)) << endl;
}	
int32_t main(){
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  //freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);	
	int t = 1;
	cin >> t;
	while(t--){
		solve();
	}
}