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>
template <typename T>
inline void read(T& x) {
  char cu = getchar();
  x = 0;
  bool fla = 0;
  while (!isdigit(cu)) {
    if (cu == '-') fla = 1;
    cu = getchar();
  }
  while (isdigit(cu)) x = x * 10 + cu - '0', cu = getchar();
  if (fla) x = -x;
}
template <typename T>
inline void printe(const T x) {
  if (x >= 10) printe(x / 10);
  putchar(x % 10 + '0');
}
template <typename T>
inline void print(const T x) {
  if (x < 0)
    putchar('-'), printe(-x);
  else
    printe(x);
}
template <typename T>
inline T min(const T a, const T b) {
  return a < b ? a : b;
}
template <typename T>
inline T max(const T a, const T b) {
  return a > b ? a : b;
}
template <typename T>
inline void mind(T& a, const T b) {
  a = a < b ? a : b;
}
const int maxn = 300001, maxm = 600001;
int n, q, dep[maxn];
int head[maxn], nxt[maxm], tow[maxm], tmp;
long long vau1[maxm], vau2[maxm];
inline void addb(const int u, const int v, const long long w1,
                 const long long w2) {
  tmp++;
  nxt[tmp] = head[u];
  head[u] = tmp;
  tow[tmp] = v;
  vau1[tmp] = w1;
  vau2[tmp] = w2;
}
long long g[maxn];
void dfs1(const int u, const int fa) {
  for (register int i = head[u]; i; i = nxt[i]) {
    const int v = tow[i];
    if (v == fa) continue;
    dep[v] = dep[u] + 1;
    dfs1(v, u);
    g[u] = min(g[u], vau1[i] + vau2[i] + g[v]);
  }
}
long long f[maxn][21][2][2];
int p[maxn][21];
void dfs2(const int u, const int fa) {
  for (register int i = head[u]; i; i = nxt[i]) {
    const int v = tow[i];
    if (v == fa) continue;
    g[v] = min(g[v], vau1[i] + vau2[i] + g[u]);
    f[v][0][0][0] = vau1[i];
    f[v][0][0][1] = g[v] + vau2[i];
    mind(f[v][0][0][0], f[v][0][0][1] + g[u]);
    mind(f[v][0][0][1], f[v][0][0][0] + g[u]);
    f[v][0][1][0] = g[v] + vau1[i];
    f[v][0][1][1] = vau2[i];
    mind(f[v][0][1][0], f[v][0][1][1] + g[u]);
    mind(f[v][0][1][1], f[v][0][1][0] + g[u]);
    p[v][0] = u;
    dfs2(v, u);
  }
}
long long dpu[2], dpv[2], dp[2];
void C() {
  std::swap(dpu[0], dpv[0]);
  std::swap(dpu[1], dpv[1]);
}
void CP(long long* D) {
  dp[0] = D[0];
  dp[1] = D[1];
}
long long lca(int u, int v) {
  if (u & 1)
    u = (u + 1) >> 1, dpu[0] = 0, dpu[1] = g[u];
  else
    u = (u + 1) >> 1, dpu[0] = g[u], dpu[1] = 0;
  if (v & 1)
    v = (v + 1) >> 1, dpv[0] = 0, dpv[1] = g[v];
  else
    v = (v + 1) >> 1, dpv[0] = g[v], dpv[1] = 0;
  if (dep[u] < dep[v]) std::swap(u, v), C();
  const int DEP = dep[u] - dep[v];
  for (register int i = 0; i <= 20; i++)
    if (DEP & (1 << i)) {
      CP(dpu);
      dpu[0] = min(dp[0] + f[u][i][0][0], dp[1] + f[u][i][1][0]);
      dpu[1] = min(dp[0] + f[u][i][0][1], dp[1] + f[u][i][1][1]);
      u = p[u][i];
      mind(dpu[0], dpu[1] + g[u]);
      mind(dpu[1], dpu[0] + g[u]);
    }
  if (u == v) return min(dpu[0] + dpv[0], dpu[1] + dpv[1]);
  for (register int i = 20; i >= 0; i--)
    if (p[u][i] != p[v][i]) {
      CP(dpu);
      dpu[0] = min(dp[0] + f[u][i][0][0], dp[1] + f[u][i][1][0]);
      dpu[1] = min(dp[0] + f[u][i][0][1], dp[1] + f[u][i][1][1]);
      u = p[u][i];
      mind(dpu[0], dpu[1] + g[u]);
      mind(dpu[1], dpu[0] + g[u]);
      CP(dpv);
      dpv[0] = min(dp[0] + f[v][i][0][0], dpv[1] + f[v][i][1][0]);
      dpv[1] = min(dp[0] + f[v][i][0][1], dpv[1] + f[v][i][1][1]);
      v = p[v][i];
      mind(dpv[0], dpv[1] + g[v]);
      mind(dpv[1], dpv[0] + g[v]);
    }
  CP(dpu);
  dpu[0] = min(dp[0] + f[u][0][0][0], dp[1] + f[u][0][1][0]);
  dpu[1] = min(dp[0] + f[u][0][0][1], dp[1] + f[u][0][1][1]);
  u = p[u][0];
  mind(dpu[0], dpu[1] + g[u]);
  mind(dpu[1], dpu[0] + g[u]);
  CP(dpv);
  dpv[0] = min(dp[0] + f[v][0][0][0], dpv[1] + f[v][0][1][0]);
  dpv[1] = min(dp[0] + f[v][0][0][1], dpv[1] + f[v][0][1][1]);
  v = p[v][0];
  mind(dpv[0], dpv[1] + g[v]);
  mind(dpv[1], dpv[0] + g[v]);
  return min(dpu[0] + dpv[0], dpu[1] + dpv[1]);
}
int main() {
  read(n);
  for (register int i = 1; i <= n; i++) read(g[i]);
  for (register int i = 1; i < n; i++) {
    int u, v;
    long long w1, w2;
    read(u), read(v), read(w1), read(w2);
    addb(u, v, w1, w2);
    addb(v, u, w1, w2);
  }
  dfs1(1, 0);
  p[1][0] = 1, dfs2(1, 0);
  for (register int j = 1; j <= 20; j++)
    for (register int i = 1; i <= n; i++) {
      const int P = p[i][j - 1];
      p[i][j] = p[P][j - 1];
      const int T = p[i][j];
      f[i][j][0][0] = min(f[i][j - 1][0][0] + f[P][j - 1][0][0],
                          f[i][j - 1][0][1] + f[P][j - 1][1][0]);
      f[i][j][0][1] = min(f[i][j - 1][0][0] + f[P][j - 1][0][1],
                          f[i][j - 1][0][1] + f[P][j - 1][1][1]);
      mind(f[i][j][0][0], f[i][j][0][1] + g[T]);
      mind(f[i][j][0][1], f[i][j][0][0] + g[T]);
      f[i][j][1][0] = min(f[i][j - 1][1][0] + f[P][j - 1][0][0],
                          f[i][j - 1][1][1] + f[P][j - 1][1][0]);
      f[i][j][1][1] = min(f[i][j - 1][1][0] + f[P][j - 1][0][1],
                          f[i][j - 1][1][1] + f[P][j - 1][1][1]);
      mind(f[i][j][1][0], f[i][j][1][1] + g[T]);
      mind(f[i][j][1][1], f[i][j][1][0] + g[T]);
    }
  read(q);
  while (q--) {
    int u, v;
    read(u), read(v);
    print(lca(u, v)), putchar('\n');
  }
  return 0;
}