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 + 10, LOG = 19;
struct data {
  int nt, to;
} a[N << 1];
long long pre[N][2], dis[N][LOG + 1][2][2], wa[N << 1], wb[N << 1], wc[N << 1],
    v[N], dp[N][2], d[N];
int mn[N], head[N], dep[N], f[N][LOG + 1], cnt = 0, n;
void add(int x, int y) {
  a[++cnt].to = y, a[cnt].nt = head[x], head[x] = cnt;
  a[++cnt].to = x, a[cnt].nt = head[y], head[y] = cnt;
}
void dfs(int u, int fa) {
  f[u][0] = fa, dep[u] = dep[fa] + 1;
  dp[u][0] = v[u], mn[u] = 0;
  for (int i = head[u]; i; i = a[i].nt) {
    int to = a[i].to;
    if (to == fa) continue;
    pre[to][0] = wa[i], pre[to][1] = wb[i];
    dfs(to, u);
    long long pos = dp[to][0] + wc[i];
    if (pos <= dp[u][0]) {
      dp[u][1] = dp[u][0];
      dp[u][0] = pos, mn[u] = to;
    } else if (pos <= dp[u][1]) {
      dp[u][1] = pos;
    }
  }
}
void sfd(int u, int fa) {
  for (int i = head[u]; i; i = a[i].nt) {
    int to = a[i].to;
    if (to == fa) continue;
    d[to] = min(d[to], d[u] + wc[i]);
    if (mn[u] == to)
      d[to] = min(d[to], dp[u][1] + wc[i]);
    else
      d[to] = min(d[to], dp[u][0] + wc[i]);
    sfd(to, u);
  }
}
void getdis() {
  memset(dp, 0x3f, sizeof dp);
  memset(d, 0x3f, sizeof d);
  d[1] = v[1];
  dfs(1, 0);
  sfd(1, 0);
  for (int i = 1; i <= n; ++i) d[i] = min(d[i], dp[i][0]);
}
void get() {
  for (int i = 1; i <= LOG; ++i)
    for (int j = 1; j <= n; ++j) {
      f[j][i] = f[f[j][i - 1]][i - 1];
    }
}
int GetLCA(int A, int B) {
  if (dep[A] > dep[B]) swap(A, B);
  for (int i = LOG; i >= 0; --i) {
    if (dep[f[B][i]] >= dep[A]) B = f[B][i];
  }
  if (A == B) return A;
  for (int i = LOG; i >= 0; --i) {
    if (f[A][i] != f[B][i]) {
      A = f[A][i], B = f[B][i];
    }
  }
  return f[A][0];
}
long long len[2], nen[2];
long long go(int x, int y, int be, int ed) {
  if (x == y) {
    if (be == ed)
      return 0ll;
    else
      return d[x];
  }
  memset(len, 0x3f, sizeof len);
  len[be] = 0;
  for (int i = LOG; i >= 0; --i) {
    if (dep[f[x][i]] >= dep[y]) {
      memset(nen, 0x3f, sizeof nen);
      for (int j = 0; j <= 1; ++j) {
        for (int t = 0; t <= 1; ++t)
          nen[t] = min(nen[t], len[j] + dis[x][i][j][t]);
      }
      for (int j = 0; j <= 1; ++j) len[j] = nen[j];
      x = f[x][i];
    }
  }
  return len[ed];
}
long long cal(int x, int y) {
  int p1 = 1, p2 = 1;
  if (x & 1) p1 = 0;
  if (y & 1) p2 = 0;
  x = (x + 1) / 2, y = (y + 1) / 2;
  int lca = GetLCA(x, y);
  long long ans1 = go(x, lca, p1, 0) + go(y, lca, p2, 0);
  long long ans2 = go(x, lca, p1, 1) + go(y, lca, p2, 1);
  return min(ans1, ans2);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%lld", &v[i]);
  }
  for (int i = 1; i <= n - 1; ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    add(x, y);
    scanf("%lld%lld", &wa[cnt], &wb[cnt]);
    wa[cnt - 1] = wa[cnt], wb[cnt - 1] = wb[cnt];
  }
  for (int i = 1; i <= cnt; ++i) {
    wc[i] = wa[i] + wb[i];
  }
  getdis(), get();
  memset(dis, 0x3f, sizeof dis);
  for (int i = 1; i <= n; ++i) {
    int fa = f[i][0];
    dis[i][0][0][0] = min(pre[i][0], pre[i][1] + d[fa] + d[i]);
    dis[i][0][0][1] = min(pre[i][0] + d[fa], d[i] + pre[i][1]);
    dis[i][0][1][0] = min(pre[i][1] + d[fa], d[i] + pre[i][0]);
    dis[i][0][1][1] = min(pre[i][1], pre[i][0] + d[fa] + d[i]);
  }
  for (int i = 1; i <= LOG; ++i) {
    for (int j = 1; j <= n; ++j) {
      for (int k = 0; k <= 1; ++k)
        for (int t = 0; t <= 1; ++t) {
          for (int l = 0; l <= 1; ++l) {
            dis[j][i][k][l] =
                min(dis[j][i][k][l],
                    dis[j][i - 1][k][t] + dis[f[j][i - 1]][i - 1][t][l]);
          }
        }
    }
  }
  int q;
  scanf("%d", &q);
  for (int o = 1; o <= q; ++o) {
    int x, y;
    scanf("%d%d", &x, &y);
    printf("%lld\n", cal(x, y));
  }
  return 0;
}