#include <bits/stdc++.h>
#define f(c,a,b) for(int c=a; c<=b; c++)
#define N 200005
#define pb push_back

using namespace std;
typedef double db;
typedef long long ll;
vector<int> g[N];
int fa[N], n, cs[N]={0,1};
ll dp[N]={0}, a[N];

void init(){ f(i,2,n) { g[i].clear(); cs[i]=-1; } }
int dcs(int u){ return cs[u] = ( (cs[u]==-1)?dcs(fa[u])+1:cs[u] ); }

int main(){
	// freopen("owo.in","r",stdin);
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int t;
	cin>> t;
	g[1].pb(1);
	while(t--){
		cin >> n;
		init();
		f(i,2,n) cin >> fa[i];
		f(i,2,n) cin >> a[i];
		f(i,2,n) g[dcs(i)].pb(i);
		int i;

		// for (int I=2; !g[I].empty(); I++) {
		// 	for (auto x : g[I]) {
		// 		cout<<x<<'['<<a[x]<<']'<< ' ';
		// 	}
		// 	cout<<endl;
		// }

		for (i=2; !g[i].empty(); i++) {
			ll ma=0, mi=1e10, maplu=0, mamin=-1e10;
			for (auto x : g[i]) {
				ma = max(a[x], ma);
				mi = min(a[x], mi);
				maplu = max( dp[fa[x]]+a[x], maplu );
				mamin = max( dp[fa[x]]-a[x], mamin );
			}
			for (auto x : g[i]) {
				ll t1 = max(abs(a[x]-ma), abs(a[x]-mi))+dp[fa[x]];
				ll t2 = max( maplu-a[x], mamin+a[x]);
				// cout<<t1<<' '<<t2<<"   ";
				dp[x] = max( t1, t2 );
				// cout<<"dp["<<x<<"]="<<dp[x]<<' ';
			}
			// cout<<endl;
		}
		ll ans = 0;
		for (auto x : g[i-1]) ans = max(ans, dp[x]);
		cout << ans << endl;
	}
	return 0;
}