#include<bits/stdc++.h>
#define LL long long
#define N 200010
using namespace std;
int dis[N],n,fa[N];
LL inf=1e18;
LL f[N],a[N];
vector<int>g[N],b[N];
void dfs(int x){
	for(int to:g[x]){
		if(to==fa[x])continue;
		fa[to]=x;
		dis[to]=dis[x]+1;
		b[dis[to]].push_back(to);
		dfs(to);
	}
}

int main(){
	int qt;
	scanf("%d",&qt);
	while(qt--){
		scanf("%d",&n);
		int x;
		for(int i=0;i<=n;i++){
			fa[i]=f[i]=0;
			g[i].clear();b[i].clear();
			dis[i]=0;
		}
		for(int i=2;i<=n;i++){
			scanf("%d",&x);
			g[i].push_back(x);
			g[x].push_back(i);
		}
		for(int i=2;i<=n;i++)scanf("%lld",&a[i]);
		dfs(1);
		
		int d=0;
		for(int i=1;i<=n;i++)
			d=max(d,dis[i]);
		LL ans=0;
		for(int i=1;i<=d;i++){
			LL x1=-inf,x3=-inf,x4=-inf,x2=inf;
			for(int x:b[i]){
				x1=max(x1,a[x]);
				x2=min(x2,a[x]);
				x3=max(x3,f[fa[x]]+a[x]);
				x4=max(x4,f[fa[x]]-a[x]);
			}
			for(int x:b[i]){
				int y=fa[x];
				f[x]=max(f[x],f[y]+max(x1-a[x],a[x]-x2));
				f[x]=max(f[x],max(x3-a[x],x4+a[x]));
				ans=max(ans,f[x]);
			}
		}
		printf("%lld\n",ans);
	}
	return 0;
}