#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200005;
const long long MINF = 0;
vector<pair<int, int>> g[MAXN];
long long W[MAXN];
long long dp1[MAXN], dp2[MAXN], dp3[MAXN];
long long inc[MAXN], exc[MAXN];
long long res;
void dfs(int v, int p) {
vector<long long> child_inc;
for (auto [to, cost] : g[v]) {
if (to == p) continue;
dp1[to] = dp1[v] + W[to];
dp2[to] = dp2[v] + cost;
dp3[to] = dp1[to] - 2 * dp2[to];
dfs(to, v);
child_inc.push_back(inc[to]);
}
if (child_inc.size() >= 2) {
sort(child_inc.rbegin(), child_inc.rend());
long long local_pair = child_inc[0] + child_inc[1] - 2 * dp3[v];
res = max(res, local_pair + dp1[v]);
}
for (auto [to, _] : g[v]) {
if (to == p) continue;
res = max(res, exc[to] - dp3[v] + dp1[v]);
}
if (!child_inc.empty()) {
exc[v] = *max_element(child_inc.begin(), child_inc.end());
} else {
exc[v] = MINF;
}
inc[v] = max(dp3[v], exc[v]);
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int T; cin >> T;
while (T--) {
int N; cin >> N;
for (int i = 1; i <= N; ++i) {
cin >> W[i];
g[i].clear();
inc[i] = exc[i] = MINF;
}
for (int i = 1; i < N; ++i) {
int u, v, c;
cin >> u >> v >> c;
g[u].emplace_back(v, c);
g[v].emplace_back(u, c);
}
dp1[1] = W[1];
dp2[1] = 0;
dp3[1] = dp1[1] - 2 * dp2[1];
res = MINF;
dfs(1, -1);
cout << max(res, 0LL) << '\n';
}
return 0;
}