#include <bits/stdc++.h>
using namespace std;
int gint() {
  int ret = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    ret = ret * 10 + c - '0';
    c = getchar();
  }
  return ret * f;
}
int n, q, cte;
int a[301000], fe[301000], fa[301000], head[301000];
long long f[301000][3], g[301000][2], vsum[301000], esum[301000];
struct Edge {
  int to, nxt, val;
} edge[301000 * 2];
void ae(int u, int v, int w) {
  cte++;
  edge[cte].to = v, edge[cte].val = w;
  edge[cte].nxt = head[u], head[u] = cte;
}
int use[301000], dep[301000];
long long dis[301000], sum[301000];
int ff[301000][20];
void dfs1(int u, int dad) {
  ff[u][0] = u;
  for (int j = head[u]; j; j = edge[j].nxt) {
    int v = edge[j].to;
    if (v == dad) continue;
    dep[v] = dep[u] + 1, fa[v] = u, ff[v][1] = u, fe[v] = edge[j].val;
    dis[v] = dis[u] + edge[j].val;
    vsum[v] = vsum[u] + a[v];
    esum[v] = esum[u] + edge[j].val;
    dfs1(v, u);
    if (f[v][0] + a[v] - 2ll * edge[j].val > 0)
      use[v] = 1, f[u][0] += f[v][0] + a[v] - 2ll * edge[j].val;
  }
}
void dfs2(int u) {
  for (int j = head[u]; j; j = edge[j].nxt) {
    int v = edge[j].to;
    if (v == fa[u]) continue;
    if (use[v]) {
      f[v][1] = f[u][0] - (f[v][0] + a[v] - 2ll * edge[j].val);
      f[v][2] = max(0ll, f[u][2] + f[v][1] + a[u] - 2ll * edge[j].val);
    } else {
      f[v][1] = f[u][0];
      f[v][2] = max(0ll, f[u][2] + f[v][1] + a[u] - 2ll * edge[j].val);
    }
    g[v][0] = g[u][0] + f[v][0];
    g[v][1] = g[u][1] + f[v][1];
    dfs2(v);
  }
}
void get_lca() {
  for (int j = 2; j <= 19; j++)
    for (int i = 1; i <= n; i++) ff[i][j] = ff[ff[i][j - 1]][j - 1];
}
int Lca(int x, int y, int &fx, int &fy) {
  int px = x, py = y, ans, dx, dy, flag = 1;
  if (dep[x] < dep[y]) swap(x, y);
  for (int i = 19; i >= 0; i--)
    if (dep[ff[x][i]] >= dep[y]) x = ff[x][i];
  for (int i = 19; i >= 0; i--)
    if (ff[x][i] != ff[y][i])
      x = ff[x][i], y = ff[y][i];
    else
      ans = ff[x][i];
  x = px, y = py;
  dx = dep[ans] + 1;
  dy = dep[ans] + 1;
  for (int i = 19; i >= 0; i--) {
    if (dep[ff[x][i]] >= dx) x = ff[x][i];
    if (dep[ff[y][i]] >= dy) y = ff[y][i];
  }
  fx = x, fy = y;
  return ans;
}
long long solve(int x, int y) {
  if (x == y)
    return f[x][0] + f[x][2] + a[x];
  else if (fa[x] == y)
    return f[x][0] + f[x][1] + f[y][2] + a[x] + a[y] - fe[x];
  else if (fa[y] == x)
    return f[y][0] + f[y][1] + f[x][2] + a[x] + a[y] - fe[y];
  int fx, fy, lca;
  lca = Lca(x, y, fx, fy);
  long long ans = 0;
  ans += (vsum[x] + vsum[y] - vsum[lca] - vsum[fa[lca]]) -
         (esum[x] + esum[y] - 2ll * esum[lca]);
  ans += f[x][0] + f[y][0];
  if (y == fy && x != fx) {
    ans += g[x][1] + g[y][1] - 2ll * g[lca][1] - f[fx][1];
    if (use[fx]) ans -= f[fx][0] + a[fx] - 2ll * fe[fx];
  } else {
    ans += g[x][1] + g[y][1] - 2ll * g[lca][1] - f[fy][1];
    if (use[fy]) ans -= f[fy][0] + a[fy] - 2ll * fe[fy];
  }
  ans += f[lca][2];
  return ans;
}
int main() {
  scanf("%d%d", &n, &q);
  int x, y, w;
  for (int i = 1; i <= n; i++) a[i] = gint();
  for (int i = 1; i < n; i++)
    x = gint(), y = gint(), w = gint(), ae(x, y, w), ae(y, x, w);
  dep[1] = 1;
  vsum[1] = a[1], dfs1(1, -1);
  g[1][0] = f[1][0], dfs2(1);
  get_lca();
  for (int i = 1; i <= q; i++)
    x = gint(), y = gint(), printf("%lld\n", solve(x, y));
  return 0;
}

### Prompt

Generate a CPP solution to the following problem:

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 gint() {
  int ret = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    ret = ret * 10 + c - '0';
    c = getchar();
  }
  return ret * f;
}
int n, q, cte;
int a[301000], fe[301000], fa[301000], head[301000];
long long f[301000][3], g[301000][2], vsum[301000], esum[301000];
struct Edge {
  int to, nxt, val;
} edge[301000 * 2];
void ae(int u, int v, int w) {
  cte++;
  edge[cte].to = v, edge[cte].val = w;
  edge[cte].nxt = head[u], head[u] = cte;
}
int use[301000], dep[301000];
long long dis[301000], sum[301000];
int ff[301000][20];
void dfs1(int u, int dad) {
  ff[u][0] = u;
  for (int j = head[u]; j; j = edge[j].nxt) {
    int v = edge[j].to;
    if (v == dad) continue;
    dep[v] = dep[u] + 1, fa[v] = u, ff[v][1] = u, fe[v] = edge[j].val;
    dis[v] = dis[u] + edge[j].val;
    vsum[v] = vsum[u] + a[v];
    esum[v] = esum[u] + edge[j].val;
    dfs1(v, u);
    if (f[v][0] + a[v] - 2ll * edge[j].val > 0)
      use[v] = 1, f[u][0] += f[v][0] + a[v] - 2ll * edge[j].val;
  }
}
void dfs2(int u) {
  for (int j = head[u]; j; j = edge[j].nxt) {
    int v = edge[j].to;
    if (v == fa[u]) continue;
    if (use[v]) {
      f[v][1] = f[u][0] - (f[v][0] + a[v] - 2ll * edge[j].val);
      f[v][2] = max(0ll, f[u][2] + f[v][1] + a[u] - 2ll * edge[j].val);
    } else {
      f[v][1] = f[u][0];
      f[v][2] = max(0ll, f[u][2] + f[v][1] + a[u] - 2ll * edge[j].val);
    }
    g[v][0] = g[u][0] + f[v][0];
    g[v][1] = g[u][1] + f[v][1];
    dfs2(v);
  }
}
void get_lca() {
  for (int j = 2; j <= 19; j++)
    for (int i = 1; i <= n; i++) ff[i][j] = ff[ff[i][j - 1]][j - 1];
}
int Lca(int x, int y, int &fx, int &fy) {
  int px = x, py = y, ans, dx, dy, flag = 1;
  if (dep[x] < dep[y]) swap(x, y);
  for (int i = 19; i >= 0; i--)
    if (dep[ff[x][i]] >= dep[y]) x = ff[x][i];
  for (int i = 19; i >= 0; i--)
    if (ff[x][i] != ff[y][i])
      x = ff[x][i], y = ff[y][i];
    else
      ans = ff[x][i];
  x = px, y = py;
  dx = dep[ans] + 1;
  dy = dep[ans] + 1;
  for (int i = 19; i >= 0; i--) {
    if (dep[ff[x][i]] >= dx) x = ff[x][i];
    if (dep[ff[y][i]] >= dy) y = ff[y][i];
  }
  fx = x, fy = y;
  return ans;
}
long long solve(int x, int y) {
  if (x == y)
    return f[x][0] + f[x][2] + a[x];
  else if (fa[x] == y)
    return f[x][0] + f[x][1] + f[y][2] + a[x] + a[y] - fe[x];
  else if (fa[y] == x)
    return f[y][0] + f[y][1] + f[x][2] + a[x] + a[y] - fe[y];
  int fx, fy, lca;
  lca = Lca(x, y, fx, fy);
  long long ans = 0;
  ans += (vsum[x] + vsum[y] - vsum[lca] - vsum[fa[lca]]) -
         (esum[x] + esum[y] - 2ll * esum[lca]);
  ans += f[x][0] + f[y][0];
  if (y == fy && x != fx) {
    ans += g[x][1] + g[y][1] - 2ll * g[lca][1] - f[fx][1];
    if (use[fx]) ans -= f[fx][0] + a[fx] - 2ll * fe[fx];
  } else {
    ans += g[x][1] + g[y][1] - 2ll * g[lca][1] - f[fy][1];
    if (use[fy]) ans -= f[fy][0] + a[fy] - 2ll * fe[fy];
  }
  ans += f[lca][2];
  return ans;
}
int main() {
  scanf("%d%d", &n, &q);
  int x, y, w;
  for (int i = 1; i <= n; i++) a[i] = gint();
  for (int i = 1; i < n; i++)
    x = gint(), y = gint(), w = gint(), ae(x, y, w), ae(y, x, w);
  dep[1] = 1;
  vsum[1] = a[1], dfs1(1, -1);
  g[1][0] = f[1][0], dfs2(1);
  get_lca();
  for (int i = 1; i <= q; i++)
    x = gint(), y = gint(), printf("%lld\n", solve(x, y));
  return 0;
}

```