#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define SZ(X) ((int)(X).size())
#define F first
#define S second
typedef long long LL;
typedef pair<int, int> PII;

const int MXN = (int)2e5 + 5;
const int INF = (int)1e9 + 7;

int T, n;
vector<vector<int>> v, layer;
vector<int> a, p;
vector<LL> dp;

void dfs(int x, int pa, int d){
	layer[d].push_back(x);
	p[x] = pa;
	for(auto i : v[x]){
		if(i == pa) continue;
		dfs(i, x, d + 1);
	}
}

int main(){
	cin >> T;
	while(T --){
		cin >> n;
		v = layer = vector<vector<int>>(n + 5);
		a = p = vector<int>(n + 5);
		dp = vector<LL>(n + 5);
		LL ans = 0;

		for(int i = 2; i <= n; i ++){
			int fr; cin >> fr;
			v[fr].push_back(i);
			v[i].push_back(fr);
		}
		for(int i = 2; i <= n; i ++) cin >> a[i];
		dfs(1, 1, 1);
		
		for(int i = 2; !layer[i].empty(); i ++){
			int mxv = -1, mnv = INF;
			LL pos = -INF, neg = -INF;
			for(auto j : layer[i]){
				mxv = max(mxv, a[j]);
				mnv = min(mnv, a[j]);
				pos = max(pos, dp[p[j]] + a[j]);
				neg = max(neg, dp[p[j]] - a[j]);
			}
			for(auto j : layer[i]){
				dp[j] = dp[p[j]] + max(mxv - a[j], a[j] - mnv);
				dp[j] = max(dp[j], max(pos - a[j], neg + a[j]));
				ans = max(ans, dp[j]);
			}
		}
		cout << ans << '\n';
	}
}

