# AC Codes：

#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
//#include <unordered_set>
//#include <unordered_map>
#include <deque>
#include <list>
#include <iomanip>
#include <algorithm>
#include <fstream>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
//#pragma GCC optimize(2)
using namespace std;
typedef long long ll;
//cout << fixed << setprecision(2);
//cout << setw(2);
const int N = 1e6 + 6, M = 1e9 + 7, INF = 0x3f3f3f3f;

int dp[N], c[N], ans;
int head[N], Next[N << 1], ver[N << 1], edge[N << 1], tot;
void add(int u, int v, int w) {
ver[++tot] = v, edge[tot] = w;
}

void dfs(int x, int fa) {
dp[x] = c[x];
for (int i = head[x]; i; i = Next[i]) {
int y = ver[i], z = edge[i];
if (y == fa) continue;
dfs(y, x);
ans = max(ans, dp[x] + dp[y] + z);
dp[x] = max(dp[x], dp[y] + z);
}
}

int main() {
//freopen("/Users/xumingfei/Desktop/ACM/test.txt", "r", stdin);
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);

int T;
cin >> T;
while (T--) {
int n;
cin >> n;
tot = 1;
for (int i = 1; i <= n; i++) head[i] = 0, dp[i] = 0;
for (int i = 2; i <= n; i++) {
int y, z;
cin >> y >> z;
}
for (int i = 1; i <= n; i++) cin >> c[i];
ans = -2e9;
dfs(1, -1);
cout << ans << '\n';
}

return 0;
}

08-08 1115
02-04 880