/*
--------------              |   /
      |                     |  /
      |                     | /
      |             *       |/          |    |         ------            *
      |                     |           |    |        /      \
      |             |       |\          |    |       |       |\          |
   \  |             |       | \         |    |       |       | \         |
    \ |             |       |  \        |    |        \     /   \        |
     V              |       |   \        \__/|         -----     \       |
*/
#include <bits/stdc++.h>
using namespace std;

#define EmiliaMyWife ios::sync_with_stdio(0); cin.tie(NULL);
using ll = int64_t;
using ull = uint64_t;
using ld = long double;
using uint = uint32_t;
const double EPS  = 1e-8;
const int INF     = 0x3F3F3F3F;
const ll LINF     = 4611686018427387903;
const int MOD     = 1e9+7;
/*--------------------------------------------------------------------------------------*/

signed main() { EmiliaMyWife
	int t;
	cin >> t;
	while(t--) {
		int n;
		cin >> n;
		vector<int> arr(n + 1), dis(n + 1), pa(n + 1);
		vector<ll> dp(n + 1);
		vector<vector<int>> edge(n + 1), owo(n);
		for(int i = 2; i <= n; i++)
			cin >> pa[i], edge[pa[i]].push_back(i);
		for(int i = 2; i <= n; i++)
			cin >> arr[i];
		function<void(int)> dfs = [&](int u) {
			owo[dis[u]].push_back(u);
			for(int v : edge[u]) {
				pa[v] = u;
				dis[v] = dis[u] + 1;
				dfs(v);
			}
		};
		dfs(1);
		for(int i = 1; i < n; i++) {
			int mx = -INF, mn = INF;
			ll a = -LINF, b = -LINF;
			for(int u : owo[i]) {
				mx = max(mx, arr[u]);
				mn = min(mn, arr[u]);
				a = max(a, dp[pa[u]] + arr[u]);
				b = max(b, dp[pa[u]] - arr[u]);
			}
			for(int u : owo[i]) {
				dp[u] = dp[pa[u]] + max(abs(mx - arr[u]), abs(mn - arr[u]));
				dp[u] = max(dp[u], max(a - arr[u], b + arr[u]));
			}
		}
		cout << *max_element(dp.begin(), dp.end()) << '\n';
	}
}
