#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5+50, INF = 0x3f3f3f3f;

ll f[N], fa[N], a[N], md;
vector<int> rt[N], d[N];

void Init(int n){
	md = 0;
	for(int i = 0;i <= n;i++){
		f[i] = 0;
		rt[i].clear();
		d[i].clear();
	}
}

void dfs(int u,int dep){
	d[dep].push_back(u);
	md = max(md,(ll)dep);
	for(int i = 0;i < rt[u].size();i++) dfs(rt[u][i],dep+1);
}

int main(){
	int t;
	scanf("%d",&t);
	while(t--){
		int n;
		scanf("%d",&n);
		Init(n);
		for(int i = 2;i <= n;i++){
			int x;
			scanf("%d",&x);
			fa[i] = x;
			rt[x].push_back(i);
		}
		for(int i = 2;i <= n;i++) scanf("%lld",&a[i]);
		dfs(1,0);
		for(int i = md;i >= 1;i--){
			ll maxd = 0, mind = INF, m1 = -INF, m2 = -INF;
			for(int j = 0;j < d[i].size();j++){
				m1 = max(m1, f[d[i][j]] - a[d[i][j]]);
				m2 = max(m2, f[d[i][j]] + a[d[i][j]]);
				maxd = max(maxd,a[d[i][j]]);
				mind = min(mind,a[d[i][j]]);
			}
//			printf("%d %lld %lld\n",i,m1,m2);
			for(int j = 0;j < d[i].size();j++){
				int u = fa[d[i][j]];
				f[u] = max(f[u],max(maxd - a[d[i][j]],a[d[i][j]] - mind)+f[d[i][j]]); //这个转移不交换的情况 
				f[u] = max(f[u], max(m1 + a[d[i][j]], m2 - a[d[i][j]])); //这个转移交换的情况 
			}
		}
//		for(int i = 1;i <= n;i++) printf("%lld ",f[i]); printf("\n");
		printf("%lld\n",f[1]);
	}
	return 0;
}