#include <algorithm>
#include <iostream>
#include <queue>
#include <set>
#include <vector>
#include <climits>

using namespace std;

const int MAX_N = 200000;

vector<int> edge[1 + MAX_N];

void run()
{
	int n;
	cin >> n;

	long long a[1 + n];

	for(int i = 0; i <= n; i++) edge[i].clear();

	for(int i = 2; i <= n; i++)
	{
		int vi;
		cin >> vi;
		edge[vi].push_back(i);
		edge[i].push_back(vi);
	}

	a[1] = 0;
	for (int i = 2; i <= n; i++)
		cin >> a[i];

	queue<int> bfsQueue;
	bfsQueue.push(1);

	int depth[1 + n];
	for (int i = 1; i <= n; i++)
		depth[i] = 0;

	depth[1] = 1;

	int parent[1 + n];
	parent[1] = 0;

	vector<int> verticesByDepth[1 + n];

	while (!bfsQueue.empty())
	{
		int u = bfsQueue.front();
		bfsQueue.pop();
		verticesByDepth[depth[u]].push_back(u);

		for (int x : edge[u])
		{
			if(depth[x]) continue;
			bfsQueue.push(x);
			depth[x] = depth[u] + 1;
			parent[x] = u;
		}
	}

    long long MaxScore[1 + n];

	vector<long long> minA(1 + n, INT_MAX), maxA(1 + n, 0);
	for (int i = 1; i <= n; i++)
	{
		minA[depth[i]] = min(minA[depth[i]], a[i]);
		maxA[depth[i]] = max(maxA[depth[i]], a[i]);
	}

	MaxScore[1] = 0;

	long long res = 0;

	for (int d = 2; d < n; d++)
	{
		long long max1 = LLONG_MIN, max2 = LLONG_MIN;
		for (int r : verticesByDepth[d])
		{
			max1 = max(max1, MaxScore[parent[r]] + a[r]);
			max2 = max(max2, MaxScore[parent[r]] - a[r]);
		}
		for (int r : verticesByDepth[d])
		{
		MaxScore[r] = 0;
		MaxScore[r] = max(MaxScore[r], MaxScore[parent[r]] + a[r] - minA[depth[r]]);
		MaxScore[r] = max(MaxScore[r], MaxScore[parent[r]] + maxA[depth[r]] - a[r]);

		MaxScore[r] = max(MaxScore[r], max1 - a[r]);
		MaxScore[r] = max(MaxScore[r], max2 + a[r]);

		res = max(res, MaxScore[r]);
		}
	}
	cout << res << '\n';
}


int main()
{
	int t;
	cin >> t;
	while(t--) run();
}
