/** Im the best because i work as hard as i possibly can **/

#pragma GCC optimize("O2")
#include <bits/stdc++.h>
using namespace std;

typedef long long                   ll;
typedef long double                 ld;
typedef pair<int,int>               pii;
typedef pair<ll,ll>                 pll;
#define all(x)                      (x).begin(),(x).end()
#define F                           first
#define S                           second
#define Mp                          make_pair
#define fast_io                     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io                     freopen("in.txt" , "r+" , stdin) ; freopen("out.txt" , "w+" , stdout);
#define endl                        "\n"

const int N = 1e6 + 10;
const ll mod = 1e9 + 7;
const ll mod2 = 998244353;
const ll inf = 1e18;
const int LOG = 22;

ll pw(ll a , ll b, ll M)  { return (!b ? 1 : (b & 1 ? (a * pw(a * a % M, b / 2, M)) % M : pw(a * a % M, b / 2, M))); }

ll dp[N];

int n, P[N], H[N], A[N];

vector < int > lev[N], G[N];

bool cmp(int v, int u)
{
	return A[v] < A[u];
}

void dfs(int v)
{
	for(auto u : G[v])
	{
		H[u] = H[v] + 1;
		dfs(u);
	}
}

void solve()
{
	scanf("%d", &n);
	for(int i = 0; i <= n + 1; i ++)
	{
		dp[i] = -inf;
		lev[i].clear();
		G[i].clear();
	}
	int d = 0;
	for(int i = 2; i <= n; i ++)
	{
		scanf("%d", &P[i]);
		G[P[i]].push_back(i);
	}
	H[0] = 0;
	dfs(1);
	for(int i = 1; i <= n; i ++) 
	{
		d = max(d, H[i]);
		lev[H[i]].push_back(i);
		if(i > 1) scanf("%d", &A[i]);
	}
	dp[1] = 0;
	ll tot = 0;
	for(int i = 1; i <= d; i ++)
	{
		if(lev[i].empty()) continue;
		sort(all(lev[i]), cmp);
		multiset < ll > st;
		for(auto v : lev[i])
		{
			st.insert(A[v] + dp[P[v]]);
		}
		for(auto v : lev[i])
		{
			dp[v] = max(dp[v], *st.crbegin() - A[v]);
			st.erase(st.find(A[v] + dp[P[v]]));
		}
		st.clear();
		reverse(all(lev[i]));
		for(auto v : lev[i])
		{
			st.insert(dp[P[v]] - A[v]);
		}
		for(auto v : lev[i])
		{
			dp[v] = max(dp[v], *st.crbegin() + A[v]);
			st.erase(st.find(dp[P[v]] - A[v]));
		}
		for(auto v : lev[i])
		{
			dp[v] = max(dp[v], dp[P[v]] + abs(A[v] - A[lev[i].back()]));
			dp[v] = max(dp[v], dp[P[v]] + abs(A[v] - A[lev[i].front()]));
			tot = max(tot, dp[v]);
		}
	}
	printf("%lld\n", tot);
}

int main()
{
	int q;
	scanf("%d", &q);
	while(q --) solve();
    return 0;
}


