#include<bits/stdc++.h>
#define int long long
#define MAXN 200010
using namespace std;
int T,n,a[MAXN];
struct Node{int to,nxt;}Edge[MAXN<<1];
int Head[MAXN],cnt_Edge;
void Add_Edge(int u,int v){
	Edge[++cnt_Edge]=(Node){v,Head[u]};
	Head[u]=cnt_Edge;
}
int dep[MAXN],d,fa[MAXN];
struct qnode{int u,val,pl,mi;};
vector<qnode>vct[MAXN];
int f[MAXN];
bool cmp(qnode a,qnode b){return a.val<b.val;}
void dfs(int u,int fat){
	dep[u]=dep[fat]+1;fa[u]=fat;d=max(d,dep[u]);
	vct[dep[u]].push_back((qnode){u,a[u],a[u],-a[u]});
	for(int i=Head[u];i;i=Edge[i].nxt){
		int v=Edge[i].to;if(v==fat)continue;
		dfs(v,u);
	}
}
signed main(){
	scanf("%lld",&T);
	while(T--){
		scanf("%lld",&n);cnt_Edge=0;
		for(int i=1;i<=n;i++)Head[i]=a[i]=dep[i]=fa[i]=f[i]=0,vct[i].clear();
		for(int i=2;i<=n;i++){
			int v;scanf("%lld",&v);
			Add_Edge(i,v);Add_Edge(v,i);
		}
		for(int i=2;i<=n;i++)scanf("%lld",&a[i]);
		dfs(1,0);
		for(int i=d-1;i;i--){
			int sz=vct[i].size(),szn=vct[i+1].size();
			sort(vct[i+1].begin(),vct[i+1].end(),cmp);
			for(int j=1;j<szn;j++)vct[i+1][j].mi=max(vct[i+1][j].mi,vct[i+1][j-1].mi);
			for(int j=szn-2;j>=0;j--)vct[i+1][j].pl=max(vct[i+1][j].pl,vct[i+1][j+1].pl);
			int mn=vct[i+1][0].val,mx=vct[i+1][szn-1].val;
			for(int j=0;j<sz;j++){
				int u=vct[i][j].u;
				for(int e=Head[u];e;e=Edge[e].nxt){
					int v=Edge[e].to;if(v==fa[u])continue;
					f[u]=max(f[u],max(abs(mn-a[v]),abs(mx-a[v]))+f[v]);
					int L=0,R=szn-1,res=szn;
					while(L<=R){
						int mid=(L+R)>>1;
						if(vct[i+1][mid].val<=a[v])L=mid+1;
						else R=mid-1,res=mid;
					}//printf("debug:%lld %lld %lld %lld\n",vct[i+1][res].val,a[v],res,szn);
					if(res!=szn)f[u]=max(f[u],vct[i+1][res].pl-a[v]);
					if(res!=0)f[u]=max(f[u],vct[i+1][res-1].mi+a[v]);
				}
				vct[i][j].pl=f[u]+a[u];
				vct[i][j].mi=f[u]-a[u];
			}
		}printf("%lld\n",f[1]);
	}
	return 0;	
}
/*
lswn ak ioi
sxw ak ioi
sto karry orz
sto ix35 orz
*/