#include <bits/stdc++.h>
using namespace std;
int n, m, a[105000 * 3], h[105000 * 3], tabl[105000 * 10][25], inr[105000 * 3],
    outr[105000 * 3], logs[105000 * 10], timr = 0, dv[105000 * 3][25];
long long dp[105000 * 3], dpt[105000 * 3], ans[105000 * 4], df[105000 * 3];
vector<long long> dpto[105000 * 3];
pair<int, int> pr[105000 * 3];
vector<pair<int, long long> > g[105000 * 3], ask[105000 * 3];
vector<int> qr;
void rec(int v, int p, int glub) {
  timr++;
  inr[v] = timr;
  pr[v].first = qr.size();
  qr.push_back(v);
  h[v] = glub;
  dpt[v] = a[v];
  dv[v][0] = p;
  for (int i = 1; i <= logs[n]; i++) dv[v][i] = dv[dv[v][i - 1]][i - 1];
  for (auto nxt : g[v]) {
    if (nxt.first == p) continue;
    rec(nxt.first, v, glub + 1);
    dpt[v] += max(0ll, dpt[nxt.first] - nxt.second * 2);
    qr.push_back(v);
  }
  timr++;
  outr[v] = timr;
  pr[v].second = qr.size();
  qr.push_back(v);
}
int lca(int a, int b) {
  if (pr[a].first > pr[b].first) swap(a, b);
  if (a == b) return a;
  if (inr[a] <= inr[b] && inr[b] <= outr[a]) return a;
  int l = pr[a].first, r = pr[b].first;
  int dst = r - l + 1;
  if (h[tabl[l][logs[dst]]] > h[tabl[r - (1 << logs[dst]) + 1][logs[dst]]])
    return tabl[r - (1 << logs[dst]) + 1][logs[dst]];
  return tabl[l][logs[dst]];
}
void upd(int pos, long long val) {
  for (; pos < 105000 * 3; pos |= (pos + 1)) df[pos] += val;
}
long long sm(int pos) {
  long long ans = 0;
  for (; pos >= 0; pos = (pos & (pos + 1)) - 1) ans += df[pos];
  return ans;
}
long long sumer(int l, int r) { return sm(r) - sm(l); }
long long fnd(int v, int nxt) {
  int pos =
      lower_bound(g[v].begin(), g[v].end(), pair<int, long long>(nxt, -1)) -
      g[v].begin();
  if (pos >= g[v].size() || g[v][pos].first != nxt) return 0ll;
  return dpto[v][pos];
}
void calc(int v, int p) {
  dp[v] = a[v];
  dpto[v].assign(int(g[v].size()), 0ll);
  for (int i = 0; i < g[v].size(); i++) {
    dp[v] += max(0ll, dpt[g[v][i].first] - g[v][i].second * 2);
    dpto[v][i] = max(0ll, dpt[g[v][i].first] - g[v][i].second * 2);
  }
  for (int i = 0; i < g[v].size(); i++) {
    if (g[v][i].first == p) continue;
    long long lst = dpt[v];
    dpt[v] = dp[v] - dpto[v][i];
    calc(g[v][i].first, v);
    dpt[v] = lst;
  }
}
void dfs(int v, int p) {
  long long ad = 0;
  if (p != -1) ad = fnd(v, p);
  upd(h[v], dp[v] - ad);
  for (auto qr : ask[v]) {
    long long fn = fnd(qr.first, dv[qr.first][0]);
    long long sm = sumer(h[qr.first] - 1, h[v]);
    ans[qr.second] += sm + fn;
  }
  for (int i = 0; i < g[v].size(); i++) {
    if (g[v][i].first == p) continue;
    long long cur = dpto[v][i] + g[v][i].second;
    upd(h[v], -cur);
    dfs(g[v][i].first, v);
    upd(h[v], cur);
  }
  upd(h[v], -(dp[v] - ad));
}
int main() {
  ios_base::sync_with_stdio(0);
  istream::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 0; i < n - 1; i++) {
    int x, y, z;
    cin >> x >> y >> z;
    g[x].push_back({y, z});
    g[y].push_back({x, z});
  }
  for (int i = 1; i <= n; i++) sort(g[i].begin(), g[i].end());
  rec(1, -1, 1);
  calc(1, -1);
  for (int i = 2; i <= qr.size(); i++) logs[i] = logs[i >> 1] + 1;
  for (int i = 0; i < qr.size(); i++) tabl[i][0] = qr[i];
  for (int lg = 1; lg <= logs[qr.size()]; lg++)
    for (int i = 0; i < qr.size(); i++)
      if (h[tabl[i][lg - 1]] <
          h[tabl[min(int(qr.size()) - 1, i + (1 << (lg - 1)))][lg - 1]])
        tabl[i][lg] = tabl[i][lg - 1];
      else
        tabl[i][lg] =
            tabl[min(int(qr.size()) - 1, i + (1 << (lg - 1)))][lg - 1];
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    int lc = lca(x, y);
    ask[x].push_back({lc, i});
    ask[y].push_back({lc, i});
    ans[i] = -dp[lc];
  }
  dfs(1, -1);
  for (int i = 0; i < m; i++) cout << ans[i] << endl;
}

### Prompt

Develop a solution in Cpp to the problem described below:

You are given a weighted tree (undirected connected graph with no cycles, loops or multiple edges) with n vertices. The edge \\{u_j, v_j\} has weight w_j. Also each vertex i has its own value a_i assigned to it.

Let's call a path starting in vertex u and ending in vertex v, where each edge can appear no more than twice (regardless of direction), a 2-path. Vertices can appear in the 2-path multiple times (even start and end vertices).

For some 2-path p profit Pr(p) = ∑_{v ∈ distinct vertices in  p}{a_v} - ∑_{e ∈ distinct edges in  p}{k_e ⋅ w_e}, where k_e is the number of times edge e appears in p. That is, vertices are counted once, but edges are counted the number of times they appear in p.

You are about to answer m queries. Each query is a pair of vertices (qu, qv). For each query find 2-path p from qu to qv with maximal profit Pr(p).

Input

The first line contains two integers n and q (2 ≤ n ≤ 3 ⋅ 10^5, 1 ≤ q ≤ 4 ⋅ 10^5) — the number of vertices in the tree and the number of queries.

The second line contains n space-separated integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9) — the values of the vertices.

Next n - 1 lines contain descriptions of edges: each line contains three space separated integers u_i, v_i and w_i (1 ≤ u_i, v_i ≤ n, u_i ≠ v_i, 1 ≤ w_i ≤ 10^9) — there is edge \\{u_i, v_i\} with weight w_i in the tree.

Next q lines contain queries (one per line). Each query contains two integers qu_i and qv_i (1 ≤ qu_i, qv_i ≤ n) — endpoints of the 2-path you need to find.

Output

For each query print one integer per line — maximal profit Pr(p) of the some 2-path p with the corresponding endpoints.

Example

Input

7 6
6 5 5 3 2 1 2
1 2 2
2 3 2
2 4 1
4 5 1
6 4 2
7 3 25
1 1
4 4
5 6
6 4
3 4
3 7


Output

9
9
9
8
12
-14

Note

Explanation of queries: 

  1. (1, 1) — one of the optimal 2-paths is the following: 1 → 2 → 4 → 5 → 4 → 2 → 3 → 2 → 1. Pr(p) = (a_1 + a_2 + a_3 + a_4 + a_5) - (2 ⋅ w(1,2) + 2 ⋅ w(2,3) + 2 ⋅ w(2,4) + 2 ⋅ w(4,5)) = 21 - 2 ⋅ 12 = 9. 
  2. (4, 4): 4 → 2 → 1 → 2 → 3 → 2 → 4. Pr(p) = (a_1 + a_2 + a_3 + a_4) - 2 ⋅ (w(1,2) + w(2,3) + w(2,4)) = 19 - 2 ⋅ 10 = 9. 
  3. (5, 6): 5 → 4 → 2 → 3 → 2 → 1 → 2 → 4 → 6. 
  4. (6, 4): 6 → 4 → 2 → 1 → 2 → 3 → 2 → 4. 
  5. (3, 4): 3 → 2 → 1 → 2 → 4. 
  6. (3, 7): 3 → 2 → 1 → 2 → 4 → 5 → 4 → 2 → 3 → 7. 

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int n, m, a[105000 * 3], h[105000 * 3], tabl[105000 * 10][25], inr[105000 * 3],
    outr[105000 * 3], logs[105000 * 10], timr = 0, dv[105000 * 3][25];
long long dp[105000 * 3], dpt[105000 * 3], ans[105000 * 4], df[105000 * 3];
vector<long long> dpto[105000 * 3];
pair<int, int> pr[105000 * 3];
vector<pair<int, long long> > g[105000 * 3], ask[105000 * 3];
vector<int> qr;
void rec(int v, int p, int glub) {
  timr++;
  inr[v] = timr;
  pr[v].first = qr.size();
  qr.push_back(v);
  h[v] = glub;
  dpt[v] = a[v];
  dv[v][0] = p;
  for (int i = 1; i <= logs[n]; i++) dv[v][i] = dv[dv[v][i - 1]][i - 1];
  for (auto nxt : g[v]) {
    if (nxt.first == p) continue;
    rec(nxt.first, v, glub + 1);
    dpt[v] += max(0ll, dpt[nxt.first] - nxt.second * 2);
    qr.push_back(v);
  }
  timr++;
  outr[v] = timr;
  pr[v].second = qr.size();
  qr.push_back(v);
}
int lca(int a, int b) {
  if (pr[a].first > pr[b].first) swap(a, b);
  if (a == b) return a;
  if (inr[a] <= inr[b] && inr[b] <= outr[a]) return a;
  int l = pr[a].first, r = pr[b].first;
  int dst = r - l + 1;
  if (h[tabl[l][logs[dst]]] > h[tabl[r - (1 << logs[dst]) + 1][logs[dst]]])
    return tabl[r - (1 << logs[dst]) + 1][logs[dst]];
  return tabl[l][logs[dst]];
}
void upd(int pos, long long val) {
  for (; pos < 105000 * 3; pos |= (pos + 1)) df[pos] += val;
}
long long sm(int pos) {
  long long ans = 0;
  for (; pos >= 0; pos = (pos & (pos + 1)) - 1) ans += df[pos];
  return ans;
}
long long sumer(int l, int r) { return sm(r) - sm(l); }
long long fnd(int v, int nxt) {
  int pos =
      lower_bound(g[v].begin(), g[v].end(), pair<int, long long>(nxt, -1)) -
      g[v].begin();
  if (pos >= g[v].size() || g[v][pos].first != nxt) return 0ll;
  return dpto[v][pos];
}
void calc(int v, int p) {
  dp[v] = a[v];
  dpto[v].assign(int(g[v].size()), 0ll);
  for (int i = 0; i < g[v].size(); i++) {
    dp[v] += max(0ll, dpt[g[v][i].first] - g[v][i].second * 2);
    dpto[v][i] = max(0ll, dpt[g[v][i].first] - g[v][i].second * 2);
  }
  for (int i = 0; i < g[v].size(); i++) {
    if (g[v][i].first == p) continue;
    long long lst = dpt[v];
    dpt[v] = dp[v] - dpto[v][i];
    calc(g[v][i].first, v);
    dpt[v] = lst;
  }
}
void dfs(int v, int p) {
  long long ad = 0;
  if (p != -1) ad = fnd(v, p);
  upd(h[v], dp[v] - ad);
  for (auto qr : ask[v]) {
    long long fn = fnd(qr.first, dv[qr.first][0]);
    long long sm = sumer(h[qr.first] - 1, h[v]);
    ans[qr.second] += sm + fn;
  }
  for (int i = 0; i < g[v].size(); i++) {
    if (g[v][i].first == p) continue;
    long long cur = dpto[v][i] + g[v][i].second;
    upd(h[v], -cur);
    dfs(g[v][i].first, v);
    upd(h[v], cur);
  }
  upd(h[v], -(dp[v] - ad));
}
int main() {
  ios_base::sync_with_stdio(0);
  istream::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 0; i < n - 1; i++) {
    int x, y, z;
    cin >> x >> y >> z;
    g[x].push_back({y, z});
    g[y].push_back({x, z});
  }
  for (int i = 1; i <= n; i++) sort(g[i].begin(), g[i].end());
  rec(1, -1, 1);
  calc(1, -1);
  for (int i = 2; i <= qr.size(); i++) logs[i] = logs[i >> 1] + 1;
  for (int i = 0; i < qr.size(); i++) tabl[i][0] = qr[i];
  for (int lg = 1; lg <= logs[qr.size()]; lg++)
    for (int i = 0; i < qr.size(); i++)
      if (h[tabl[i][lg - 1]] <
          h[tabl[min(int(qr.size()) - 1, i + (1 << (lg - 1)))][lg - 1]])
        tabl[i][lg] = tabl[i][lg - 1];
      else
        tabl[i][lg] =
            tabl[min(int(qr.size()) - 1, i + (1 << (lg - 1)))][lg - 1];
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    int lc = lca(x, y);
    ask[x].push_back({lc, i});
    ask[y].push_back({lc, i});
    ans[i] = -dp[lc];
  }
  dfs(1, -1);
  for (int i = 0; i < m; i++) cout << ans[i] << endl;
}

```