//George1123
#include <bits/stdc++.h>
using namespace std;

typedef long long i64;
typedef unsigned int u32;
typedef unsigned long long u64;
typedef vector<int> vi;
typedef pair<int,int> pii;

#define x first
#define y second
#define sz(a) (int)((a).size())
#define all(a) (a).begin(),(a).end()
#define R(i,n) for(int i=0;i<(n);++i)
#define L(i,n) for(int i=(n)-1;i>=0;--i)

constexpr int inf32=0x3f3f3f3f;
constexpr i64 inf64=0x3f3f3f3f3f3f3f3f;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);

	int cas;
	for(cin>>cas;cas--;){
		int n;
		cin>>n;
		vector<vi> adj(n);
		R(u,n)if(u){
			int v;
			cin>>v,--v;
			adj[u].push_back(v);
			adj[v].push_back(u);
		}
		
		vi a(n);
		R(u,n)if(u) cin>>a[u];
		
		vi fa(n,-1),d(n);
		vi mx(n,-inf32),mn(n,inf32);
		vector<vi> at(n);
		function<void(int)> dfs=[&](int u){
			mn[d[u]]=min(mn[d[u]],a[u]);
			mx[d[u]]=max(mx[d[u]],a[u]);
			at[d[u]].push_back(u);
			for(const int &v:adj[u]){
				if(v==fa[u]) continue;
				fa[v]=u,d[v]=d[u]+1;
				dfs(v);
			}
		};
		dfs(0);
		
		int maxd=*max_element(all(d));
		vector<i64> f(n,-inf64);
		f[0]=0;
		R(i,maxd){
			vi ds;
			for(const int &u:at[i])
				ds.push_back(a[u]);
			sort(all(ds));
			ds.erase(unique(all(ds)),ds.end());
			int sn=sz(ds);
			
			vector<i64> pg(sn+1,-inf64),sg(sn+1,-inf64);
			for(const int &u:at[i]){
				int x=lower_bound(all
				(ds),a[u])-ds.begin();
				pg[x+1]=max(pg[x+1],f[u]-a[u]);
				sg[x]=max(sg[x],f[u]+a[u]);
			}
			R(i,sn+1)if(i) pg[i]=max(pg[i],pg[i-1]);
			L(i,sn) sg[i]=max(sg[i],sg[i+1]);
			
			for(const int &u:at[i+1]){
				int x=lower_bound(all(ds),
				a[fa[u]])-ds.begin();
				f[u]=max(pg[x]+a[fa[u]],sg[x]-a[fa[u]]);
				f[u]=max(f[u],f[fa[u]]+
				max(mx[i]-a[fa[u]],a[fa[u]]-mn[i]));
			}
		}
		
//		R(u,n) cout<<f[u]<<' ';
//		cout<<'\n';
		
		i64 res=0;
		for(const int &u:at[maxd])
			res=max(res,f[u]+max(
			mx[maxd]-a[u],a[u]-mn[maxd]));
		cout<<res<<'\n';		
	}

	return 0;
}

/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
	* DON'T GET STUCK ON ONE APPROACH
*/