﻿//#pragma GCC optimize(2)
#include<bits/stdc++.h>
 
#define IOS ios::sync_with_stdio(false);cin.tie(nullptr)
#define all(x) x.begin(),x.end()
#define pb push_back
#define eb emplace_back
#define mkp make_pair
#define lc(x) ((x)<<1)
#define rc(x) (((x)<<1)|1)

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double ld;
 
const ll LINF=1e18;
const ll MOD=1e9+7;
const int INF=0x3f3f3f3f;
const int MAXN=200050;
//35000
struct E{
	int nxt,to;
}edges[2*MAXN];
int head[MAXN],p[MAXN],tot;
void Addedge(int u,int v){
	edges[++tot].nxt=head[u];
	edges[tot].to=v;
	head[u]=tot;
}
vector<int> G[MAXN];
ll dp[MAXN],a[MAXN];
void dfs(int u,int fa=0,int dep=1){
	G[dep].eb(u);p[u]=fa;
	int to;
	for(int i=head[u];~i;i=edges[i].nxt){
		to=edges[i].to;
		if(to==fa)continue;
		dfs(to,u,dep+1);
	}
}
void mainwork(int T){
	int n;
	scanf("%d",&n);
	tot=0;
	for(int i=1;i<=n;i++){
		head[i]=-1;
		dp[i]=0;
		G[i].clear();
	}
	int tmp;
	for(int i=2;i<=n;i++){
		scanf("%d",&tmp);
		Addedge(i,tmp);
		Addedge(tmp,i);
	}
	for(int i=2;i<=n;i++){
		scanf("%lld",a+i);
	}
	dfs(1);
	for(int d=2;!G[d].empty();d++){
		ll maxa=0,mina=LINF,maxsub=-LINF,maxadd=-LINF;
		for(auto &to:G[d]){
			maxa=max(maxa,a[to]);mina=min(mina,a[to]);
			maxsub=max(maxsub,dp[p[to]]-a[to]);
			maxadd=max(maxadd,dp[p[to]]+a[to]);
		}
		for(auto &to:G[d]){
			dp[to]=max(dp[to],dp[p[to]]+max(abs(maxa-a[to]),abs(mina-a[to])));
			dp[to]=max(dp[to],max(maxsub+a[to],maxadd-a[to]));
		}
	}
	ll ans=-LINF;
	for(int i=2;i<=n;i++)ans=max(ans,dp[i]);
	printf("%lld\n",ans);
	
	
}
signed main(){
	//IOS;
	#ifndef ONLINE_JUDGE
	//freopen("./in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	#endif
	int t=1;
	scanf("%lld",&t);
	//prework();
	for(int i=1;i<=t;i++){
		mainwork(i);
	}
}
