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>
void read(T &);
template <typename T>
void write(const T &);
const int iinf = 2147483647;
const long long llinf = 9223372036854775807ll;
const int N = 300005;
const int M = 20;
void getw(int u, int fa);
void dfs(int u);
long long query(int u, int v);
std::vector<std::tuple<int, long long, long long> > G[N];
int fa[N][M];
long long val[N][M][2][2];
int lg2[N];
int dep[N];
long long a[N], w[N];
int n, q;
int main() {
  read(n);
  for (int i = 2; i <= n; ++i) lg2[i] = lg2[i >> 1] + 1;
  for (int i = 1; i <= n; ++i) read(a[i]), w[i] = a[i];
  for (int i = 1; i < n; ++i) {
    int u, v;
    long long w1, w2;
    read(u), read(v), read(w1), read(w2);
    G[u].emplace_back(v, w1, w2);
    G[v].emplace_back(u, w1, w2);
  }
  getw(1, 0), getw(1, 0);
  dfs(1);
  read(q);
  while (q--) {
    int u, v;
    read(u), read(v);
    write(query(u, v)), putchar('\n');
  }
  return 0;
}
long long query(int u, int v) {
  int su = (u & 1) ^ 1, sv = (v & 1) ^ 1;
  u = (u + 1) >> 1, v = (v + 1) >> 1;
  if (dep[u] < dep[v]) std::swap(u, v), std::swap(su, sv);
  long long au[2], av[2];
  au[su] = 0, au[su ^ 1] = w[u];
  av[sv] = 0, av[sv ^ 1] = w[v];
  int diff = dep[u] - dep[v];
  for (int i = 0; i <= 18; ++i) {
    if (diff >> i & 1) {
      long long nau[2];
      for (int j = 0; j < 2; ++j)
        nau[j] =
            std::min(au[j] + val[u][i][j][j], au[j ^ 1] + val[u][i][j ^ 1][j]);
      std::swap(au, nau);
      u = fa[u][i];
    }
  }
  if (u != v) {
    for (int i = 18; i >= 0; --i) {
      if (fa[u][i] != fa[v][i]) {
        long long nau[2], nav[2];
        for (int j = 0; j < 2; ++j) {
          nau[j] = std::min(au[j] + val[u][i][j][j],
                            au[j ^ 1] + val[u][i][j ^ 1][j]);
          nav[j] = std::min(av[j] + val[v][i][j][j],
                            av[j ^ 1] + val[v][i][j ^ 1][j]);
        }
        std::swap(au, nau), std::swap(av, nav);
        u = fa[u][i], v = fa[v][i];
      }
    }
    long long nau[2], nav[2];
    for (int j = 0; j < 2; ++j) {
      nau[j] =
          std::min(au[j] + val[u][0][j][j], au[j ^ 1] + val[u][0][j ^ 1][j]);
      nav[j] =
          std::min(av[j] + val[v][0][j][j], av[j ^ 1] + val[v][0][j ^ 1][j]);
    }
    std::swap(au, nau), std::swap(av, nav);
    u = fa[u][0], v = fa[v][0];
  }
  return std::min(au[0] + av[0], au[1] + av[1]);
}
void getw(int u, int fa) {
  for (auto [v, w1, w2] : G[u]) {
    if (v == fa) continue;
    w[v] = std::min(w[v], w[u] + w1 + w2);
    getw(v, u);
    w[u] = std::min(w[u], w[v] + w1 + w2);
  }
}
void dfs(int u) {
  for (int i = 1; i <= lg2[dep[u]]; ++i) {
    fa[u][i] = fa[fa[u][i - 1]][i - 1];
    for (int j = 0; j < 2; ++j) {
      for (int k = 0; k < 2; ++k) {
        val[u][i][j][k] = llinf;
        for (int l = 0; l < 2; ++l) {
          val[u][i][j][k] =
              std::min(val[u][i][j][k],
                       val[u][i - 1][j][l] + val[fa[u][i - 1]][i - 1][l][k]);
        }
      }
    }
  }
  for (auto [v, w0, w1] : G[u]) {
    if (v == fa[u][0]) continue;
    fa[v][0] = u;
    dep[v] = dep[u] + 1;
    val[v][0][0][0] = std::min(w0, w1 + w[u] + w[v]);
    val[v][0][1][1] = std::min(w1, w0 + w[u] + w[v]);
    val[v][0][0][1] = std::min(w0 + w[u], w1 + w[v]);
    val[v][0][1][0] = std::min(w0 + w[v], w1 + w[u]);
    dfs(v);
  }
}
template <typename T>
void read(T &Re) {
  T k = 0;
  char ch = getchar();
  int flag = 1;
  while (!(ch >= '0' && ch <= '9')) {
    if (ch == '-') flag = -1;
    ch = getchar();
  }
  while ((ch >= '0' && ch <= '9')) k = k * 10 + ch - '0', ch = getchar();
  Re = flag * k;
}
template <typename T>
void write(const T &Wr) {
  if (Wr < 0) {
    putchar('-'), write(-Wr);
  } else if (Wr < 10) {
    putchar(Wr + '0');
  } else {
    write(Wr / 10), putchar((Wr % 10) + '0');
  }
}