#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
const int N=2e5+5,inf=0x7fffffff;
int n,a[N],d[N],mx[N],mn[N],maxn[N],minn[N],dp[N],Mx[N],Mn[N];
vector<int>e[N];
void dfs(int u,int fa)
{
	for(auto v:e[u]) 
		if(v!=fa) 
		{
			d[v]=d[u]+1;
			mx[u]=max(mx[u],a[v]);
			mn[u]=min(mn[u],a[v]);
			dfs(v,u);
		}
}
void dfs1(int u,int fa)
{
	
	for(auto v:e[u])
		if(v!=fa)
		{
			dp[v]=max(dp[v],dp[u]+max(a[v]-minn[d[v]],maxn[d[v]]-a[v]));
//			printf("dp[%lld] = %lld\n",v,dp[v]);
			dp[v]=max(dp[v],max(Mn[d[u]]+a[v],Mx[d[u]]-a[v]));
			dfs1(v,u);
		}
}
queue<int>q;
bool vis[N];
void bfs()
{
	q.push(1);vis[1]=1;
	Mn[d[1]]=max(Mn[d[1]],dp[1]-mn[1]);
	Mx[d[1]]=max(Mx[d[1]],dp[1]+mx[1]);
	while(q.size())
	{
		int u=q.front();q.pop();
		for(auto v:e[u])
			if(!vis[v])
			{
				dp[v]=max(dp[v],dp[u]+max(a[v]-minn[d[v]],maxn[d[v]]-a[v]));
				dp[v]=max(dp[v],max(Mn[d[u]]+a[v],Mx[d[u]]-a[v]));
				Mn[d[v]]=max(Mn[d[v]],dp[v]-mn[v]);
				Mx[d[v]]=max(Mx[d[v]],dp[v]+mx[v]);
				q.push(v);vis[v]=1;
			}
	}
}

signed main()
{
	int T;
	scanf("%lld",&T);
	while(T--)
	{
		scanf("%lld",&n);
		for(int i=0;i<=n;i++) mx[i]=maxn[i]=dp[i]=Mx[i]=vis[i]=0,mn[i]=minn[i]=inf,Mn[i]=-inf;
		for(int i=1;i<=n;i++) e[i].clear();
		for(int i=2,x;i<=n;i++) scanf("%lld",&x),e[i].pb(x),e[x].pb(i); 
		for(int i=2;i<=n;i++) scanf("%lld",&a[i]);
		dfs(1,0);for(int i=2;i<=n;i++) maxn[d[i]]=max(maxn[d[i]],a[i]),minn[d[i]]=min(minn[d[i]],a[i]);
//		for(int i=1;i<=n;i++) printf("mn[%lld] = %lld\n",i,mn[i]);
//		for(int i=1;i<=n;i++) printf("d[%lld] = %lld\n",i,d[i]);
//		for(int i=0;i<=d[n];i++) printf("Mn[%lld] = %lld\n",i,Mn[i]);
//		for(int i=0;i<=d[n];i++) printf("Mn[%lld] = %lld\n",i,Mn[i]);
		bfs();int ans=0;
//		for(int i=2;i<=n;i++) printf("dp[%lld] = %lld\n",i,dp[i]);
		for(int i=2;i<=n;i++) ans=max(ans,dp[i]);
		printf("%lld\n",ans); 
	}
	return 0;
}