Problem: You are given a special undirected graph. It consists of 2n vertices numbered from 1 to 2n. The following properties hold for the graph:

  * there are exactly 3n-2 edges in the graph: n edges connect vertices having odd numbers with vertices having even numbers, n - 1 edges connect vertices having odd numbers with each other, and n - 1 edges connect vertices having even numbers with each other; 
  * for each edge (u, v) between a pair of vertices with odd numbers, there exists an edge (u + 1, v + 1), and vice versa; 
  * for each odd number u ∈ [1, 2n - 1], there exists an edge (u, u + 1); 
  * the graph is connected; moreover, if we delete all vertices with even numbers from it, and all edges incident to them, the graph will become a tree (the same applies to deleting odd vertices).



So, the graph can be represented as two trees having the same structure, and n edges connecting each vertex of the first tree to the corresponding vertex of the second tree.

Edges of the graph are weighted. The length of some simple path in the graph is the sum of weights of traversed edges.

You are given q queries to this graph; in each query, you are asked to compute the length of the shortest path between some pair of vertices in this graph. Can you answer all of the queries?

Input

The first line of the input contains one integer n (2 ≤ n ≤ 3 ⋅ 10^5).

The second line contains n integers w_{1, 2}, w_{3,4}, ..., w_{2n - 1, 2n} (1 ≤ w_{i, i + 1} ≤ 10^{12}). These integers describe the weights of the edges connecting odd vertices with even ones.

Then n-1 lines follow. i-th line contains four integers x_i, y_i, w_{i, 1} and w_{i, 2} (1 ≤ x_i, y_i ≤ n, x_i ≠ y_i, 1 ≤ w_{i, j} ≤ 10^{12}); it describes two edges: one connecting 2x_i - 1 with 2y_i - 1 and having weight w_{i, 1}; another connecting 2x_i with 2y_i and having weight w_{i, 2}.

The next line contains one integer q (1 ≤ q ≤ 6 ⋅ 10^5) — the number of queries.

Then q lines follow, i-th line contains two integers u_i and v_i (1 ≤ u_i, v_i ≤ 2n, u_i ≠ v_i), describing a query "compute the length of the shortest path between vertices u_i and v_i".

Output

Print q integers, i-th integer should be equal to the answer to the i-th query.

Example

Input


5
3 6 15 4 8
1 2 5 4
2 3 5 7
1 4 1 5
1 5 2 1
3
1 2
5 6
1 10


Output


3
15
4

Note

The graph in the first test looks like that:

<image>

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 6;
const long long inf = 2e17;
int n, q, t1, t2, cnt = 0, head[N], f[N][21], d[N];
long long t3, t4, w[N], g[4][N][21];
struct edge {
  int nxt, to;
  long long w, p;
} e[N << 1];
inline void add(int u, int v, long long w, long long p) {
  e[++cnt].nxt = head[u], e[cnt].to = v, e[cnt].w = w, e[cnt].p = p,
  head[u] = cnt;
}
inline long long read() {
  long long F = 1, T = 0;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') F = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9')
    T = (T << 3) + (T << 1) + (ch - 48), ch = getchar();
  return F * T;
}
void dfs(int x, int fa) {
  for (int i = head[x]; i; i = e[i].nxt)
    if (e[i].to != fa)
      dfs(e[i].to, x), w[x] = min(w[x], w[e[i].to] + e[i].w + e[i].p);
}
void dfs3(int x, int fa) {
  for (int i = head[x]; i; i = e[i].nxt)
    if (e[i].to != fa)
      w[e[i].to] = min(w[e[i].to], w[x] + e[i].w + e[i].p), dfs3(e[i].to, x);
}
void dfs2(int x, int fa) {
  f[x][0] = fa, d[x] = d[fa] + 1;
  for (int i = 1; i <= 20; ++i) {
    f[x][i] = f[f[x][i - 1]][i - 1];
    g[0][x][i] = min(g[0][x][i - 1] + g[0][f[x][i - 1]][i - 1],
                     g[2][x][i - 1] + g[1][f[x][i - 1]][i - 1]),
    g[1][x][i] = min(g[1][x][i - 1] + g[0][f[x][i - 1]][i - 1],
                     g[3][x][i - 1] + g[1][f[x][i - 1]][i - 1]);
    g[2][x][i] = min(g[0][x][i - 1] + g[2][f[x][i - 1]][i - 1],
                     g[2][x][i - 1] + g[3][f[x][i - 1]][i - 1]),
    g[3][x][i] = min(g[1][x][i - 1] + g[2][f[x][i - 1]][i - 1],
                     g[3][x][i - 1] + g[3][f[x][i - 1]][i - 1]);
  }
  for (int i = head[x]; i; i = e[i].nxt)
    if (e[i].to != fa) {
      g[0][e[i].to][0] = min(e[i].w, w[e[i].to] + e[i].p + w[x]),
      g[3][e[i].to][0] = min(e[i].p, w[e[i].to] + e[i].w + w[x]);
      g[1][e[i].to][0] = min(e[i].p + w[x], e[i].w + w[e[i].to]),
      g[2][e[i].to][0] = min(e[i].p + w[e[i].to], e[i].w + w[x]),
      dfs2(e[i].to, x);
    }
}
long long lca(int u, int v, int x, int y) {
  int pp = 0, qq = 0;
  if (u == v) return w[u];
  if (d[u] < d[v]) swap(u, v), swap(x, y);
  long long ans[2][2][4];
  memset(ans, 0, sizeof(ans)),
      ans[0][0][x ^ 1] = ans[0][0][2 + (x ^ 1)] = inf,
                    ans[0][1][y ^ 1] = ans[0][1][2 + (y ^ 1)] = inf;
  if (x == 1)
    ans[0][0][1] = inf;
  else
    ans[0][0][2] = inf;
  if (y == 1)
    ans[0][1][1] = inf;
  else
    ans[0][1][2] = inf;
  for (int i = 20; i >= 0; --i)
    if (d[u] >= d[v] + (1 << i)) {
      pp ^= 1;
      ans[pp][0][0] =
          min(ans[pp ^ 1][0][0] + g[0][u][i], ans[pp ^ 1][0][2] + g[1][u][i]),
      ans[pp][0][1] =
          min(ans[pp ^ 1][0][1] + g[0][u][i], ans[pp ^ 1][0][3] + g[1][u][i]);
      ans[pp][0][2] =
          min(ans[pp ^ 1][0][0] + g[2][u][i], ans[pp ^ 1][0][2] + g[3][u][i]),
      ans[pp][0][3] =
          min(ans[pp ^ 1][0][1] + g[2][u][i], ans[pp ^ 1][0][3] + g[3][u][i]),
      u = f[u][i];
    }
  if (u == v) return ans[pp][0][x + (y << 1)];
  for (int i = 20; i >= 0; --i)
    if (f[u][i] != f[v][i]) {
      pp ^= 1, qq ^= 1;
      ans[qq][1][0] =
          min(ans[qq ^ 1][1][0] + g[0][v][i], ans[qq ^ 1][1][2] + g[1][v][i]),
      ans[qq][1][1] =
          min(ans[qq ^ 1][1][1] + g[0][v][i], ans[qq ^ 1][1][3] + g[1][v][i]);
      ans[qq][1][2] =
          min(ans[qq ^ 1][1][0] + g[2][v][i], ans[qq ^ 1][1][2] + g[3][v][i]),
      ans[qq][1][3] =
          min(ans[qq ^ 1][1][1] + g[2][v][i], ans[qq ^ 1][1][3] + g[3][v][i]),
      v = f[v][i];
      ans[pp][0][0] =
          min(ans[pp ^ 1][0][0] + g[0][u][i], ans[pp ^ 1][0][2] + g[1][u][i]),
      ans[pp][0][1] =
          min(ans[pp ^ 1][0][1] + g[0][u][i], ans[pp ^ 1][0][3] + g[1][u][i]);
      ans[pp][0][2] =
          min(ans[pp ^ 1][0][0] + g[2][u][i], ans[pp ^ 1][0][2] + g[3][u][i]),
      ans[pp][0][3] =
          min(ans[pp ^ 1][0][1] + g[2][u][i], ans[pp ^ 1][0][3] + g[3][u][i]),
      u = f[u][i];
    }
  pp ^= 1, qq ^= 1;
  ans[qq][1][0] =
      min(ans[qq ^ 1][1][0] + g[0][v][0], ans[qq ^ 1][1][2] + g[1][v][0]),
  ans[qq][1][1] =
      min(ans[qq ^ 1][1][1] + g[0][v][0], ans[qq ^ 1][1][3] + g[1][v][0]);
  ans[qq][1][2] =
      min(ans[qq ^ 1][1][0] + g[2][v][0], ans[qq ^ 1][1][2] + g[3][v][0]),
  ans[qq][1][3] =
      min(ans[qq ^ 1][1][1] + g[2][v][0], ans[qq ^ 1][1][3] + g[3][v][0]),
  v = f[v][0];
  ans[pp][0][0] =
      min(ans[pp ^ 1][0][0] + g[0][u][0], ans[pp ^ 1][0][2] + g[1][u][0]),
  ans[pp][0][1] =
      min(ans[pp ^ 1][0][1] + g[0][u][0], ans[pp ^ 1][0][3] + g[1][u][0]);
  ans[pp][0][2] =
      min(ans[pp ^ 1][0][0] + g[2][u][0], ans[pp ^ 1][0][2] + g[3][u][0]),
  ans[pp][0][3] =
      min(ans[pp ^ 1][0][1] + g[2][u][0], ans[pp ^ 1][0][3] + g[3][u][0]),
  u = f[u][0];
  return min(ans[pp][0][x] + ans[qq][1][y],
             ans[pp][0][x + 2] + ans[qq][1][y + 2]);
}
int main() {
  n = read();
  for (int i = 1; i <= n; ++i) w[i] = read();
  for (int i = 1; i < n; ++i)
    t1 = read(), t2 = read(), t3 = read(), t4 = read(), add(t1, t2, t3, t4),
    add(t2, t1, t3, t4);
  dfs(1, 0), dfs3(1, 0), dfs2(1, 0), q = read();
  for (int i = 1; i <= q; ++i)
    t1 = read(), t2 = read(),
    printf("%lld\n", lca((t1 + 1) >> 1, (t2 + 1) >> 1, !(t1 & 1), !(t2 & 1)));
  return 0;
}