#include<bits/stdc++.h>
using namespace std;
#define int long long
vector<vector<int> >v,d;
#define maxn 200010
int md,fa[maxn],de[maxn],dp[maxn],val[maxn];
void dfs(int x,int f){
	de[x]=de[f]+1;
	fa[x]=f;
	md=max(md,de[x]);
	d[de[x]].push_back(x);
	for(int y:v[x])if(y!=f)dfs(y,x);
}
void solve(){
	int n;cin>>n;
	v.clear();
	v.resize(n+1);
	d.clear();
	d.resize(n+1);
	for(int i=1;i<=n;i++)v[i].clear(),d[i].clear();
	md=0;
	for(int i=2;i<=n;i++){
		int x;cin>>x;
		v[x].push_back(i);
		v[i].push_back(x); 
	}
	for(int i=2;i<=n;i++)cin>>val[i];
	dfs(1,0);
	dp[1]=0;
	int ans=0;
	for(int i=2;i<=md;i++){
		int a=-2e14,b=-2e14;
		for(int x:d[i])
		a=max(a,dp[fa[x]]+val[x]),b=max(b,dp[fa[x]]-val[x]);
		int mi=2e14,ma=-2e14;
		for(int x:d[i])
		mi=min(mi,val[x]),ma=max(ma,val[x]);
		for(int x:d[i])
		dp[x]=max(max(a-val[x],b+val[x]),max(dp[fa[x]]+val[x]-mi,dp[fa[x]]+ma-val[x])),ans=max(ans,dp[x]);
	}
	cout<<ans<<"\n";
}
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t;cin>>t;
	while(t--)solve();
}
