#ifndef LOCAL
#include <bits/stdc++.h>
#define debug(...)
#endif
using namespace std;
#define int long long
#define cinv(v) for (auto &it:v) cin>>it;
#define coutv(v) for (auto &it:v) cout<< it<<' '; cout<<'\n';
const int N = 2e5 + 5, INF = 1e15;
vector<pair<int,int> > g[N];
int n, a[N], sub[N], cth[N], ctp[N], ans;
void dfs_siz(int u, int p) {
sub[u] = 1;
for (auto &[v,w]: g[u]) if (!cth[v] && v ^ p) dfs_siz(v, u), sub[u] += sub[v];
}
int fc(int u, int p, int lim) {
for (auto &[v,w]: g[u]) if (!cth[v] && v ^ p && sub[v] > lim) return fc(v, u, lim);
return u;
}
void calc(int u, int p, int &b1, int &b2, int now, int lvl) {
now += a[u];
b1 = max(b1, now);
if (lvl >= 2) b2 = max(b2, now);
for (auto &[v,w]: g[u]) if (!cth[v] && v ^ p) calc(v, u, b1, b2, now - 2 * w, lvl + 1);
}
void decompose(int u, int p = 0, int h = 1) {
dfs_siz(u, 0);
u = fc(u, 0, sub[u] >> 1);
cth[u] = h, ctp[u] = p;
int now = -INF, best = -INF;
for (auto &[v,w]: g[u]) {
if (cth[v]) continue;
int b1 = a[u] - 2 * w, b2 = -INF;
calc(v, u, b1, b2, b1, 1);
now = max({now, b2, best + b1 - a[u]});
best = max(best, b1);
}
ans = max(ans, now);
for (auto &[v,w]: g[u]) if (!cth[v]) decompose(v, u, h + 1);
}
void reset() {
for (int i = 1; i <= n; ++i) {
g[i].clear();
cth[i] = 0;
}
ans = -INF;
}
void shelby() {
cin >> n;
reset();
for (int i = 1; i <= n; ++i) cin >> a[i];
for (int i = 1; i < n; ++i) {
int u, v, w;
cin >> u >> v >> w;
g[u].push_back({v, w});
g[v].push_back({u, w});
}
decompose(1);
cout << ans << '\n';
}
signed main() {
cin.tie(0)->sync_with_stdio(0);
int t = 1;
cin >> t;
for (int _ = 1; _ <= t; ++_) {
// cout << "Case " << _ << ": ";
shelby();
}
}