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;
inline long long read() {
  long long x = 0, f = 1;
  char c = getchar();
  for (; !isdigit(c); c = getchar())
    if (c == '-') f = -1;
  for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
  return x * f;
}
const long long MAXN = 300010;
const long long INF = 1e18;
long long N;
long long Node[MAXN << 1], Next[MAXN << 1], Root[MAXN + 1], cnt,
    Cost1[MAXN << 1], Cost2[MAXN << 1];
int dep[MAXN + 1], sz[MAXN + 1], fa[MAXN + 1], top[MAXN + 1], dfn[MAXN + 1],
    nod[MAXN + 1];
long long h[MAXN << 2][2][2], f[MAXN << 2][2][2];
long long w[MAXN + 1];
long long g[2], tmp[2];
int ls[MAXN << 2];
long long Ans[2][2], tAns[2][2], ug[2], vg[2];
long long C0[MAXN + 1], C1[MAXN + 1];
vector<int> vec[MAXN + 1];
int tim;
int Hvs[MAXN + 1];
inline void insert(long long u, long long v, long long c1, long long c2) {
  Node[++cnt] = v;
  Next[cnt] = Root[u];
  Root[u] = cnt;
  Cost1[cnt] = c1;
  Cost2[cnt] = c2;
}
inline void dfs(long long k, long long Fa) {
  sz[k] = 1;
  dep[k] = dep[Fa] + 1;
  fa[k] = Fa;
  for (long long x = Root[k]; x; x = Next[x]) {
    long long v = Node[x];
    if (v == Fa) continue;
    dfs(v, k);
    sz[k] += sz[v];
    if (sz[v] > sz[Hvs[k]]) Hvs[k] = v;
    C0[v] = Cost1[x];
    C1[v] = Cost2[x];
    w[k] = min(w[k], w[v] + C0[v] + C1[v]);
  }
}
inline void dfs2(long long k, long long tp) {
  vec[tp].push_back(k);
  dfn[k] = ++tim;
  nod[tim] = k;
  top[k] = tp;
  if (Hvs[k]) dfs2(Hvs[k], tp);
  for (long long x = Root[k]; x; x = Next[x]) {
    long long v = Node[x];
    if (v == fa[k] || v == Hvs[k]) continue;
    dfs2(v, v);
  }
}
inline void dfs3(long long k, long long Fa, long long upd) {
  long long v1 = INF, v2 = INF, to = -1;
  w[k] = min(w[k], upd);
  for (int x = Root[k]; x; x = Next[x]) {
    int v = Node[x];
    if (v == Fa) continue;
    long long val = w[v] + C0[v] + C1[v];
    if (val < v1)
      v2 = v1, v1 = val, to = v;
    else
      v2 = min(v2, val);
  }
  for (int x = Root[k]; x; x = Next[x]) {
    int v = Node[x];
    if (v == Fa) continue;
    dfs3(v, k, min(w[k], (to == v ? v2 : v1)) + C0[v] + C1[v]);
  }
}
inline void update(long long rt) {
  for (long long i = 0; i < 2; i++)
    for (long long j = 0; j < 2; j++) {
      h[rt][i][j] =
          min(h[rt << 1][i][1] + h[rt << 1 | 1][1][j] + C1[ls[rt << 1 | 1]],
              h[rt << 1][i][0] + h[rt << 1 | 1][0][j] + C0[ls[rt << 1 | 1]]);
    }
  ls[rt] = ls[rt << 1];
  return;
}
inline void build(long long rt, long long l, long long r) {
  if (l == r) {
    h[rt][0][0] = h[rt][1][1] = 0;
    h[rt][0][1] = h[rt][1][0] = w[nod[l]];
    ls[rt] = nod[l];
    return;
  }
  long long mid = (l + r) >> 1;
  build(rt << 1, l, mid);
  build(rt << 1 | 1, mid + 1, r);
  update(rt);
}
inline void Query(long long rt, long long l, long long r, long long L,
                  long long R) {
  if (L <= l && R >= r) {
    if (L == l) {
      memcpy(Ans, h[rt], sizeof(Ans));
      return;
    }
    for (long long i = 0; i < 2; i++)
      for (long long j = 0; j < 2; j++) tAns[i][j] = Ans[i][j];
    for (long long i = 0; i < 2; i++)
      for (long long j = 0; j < 2; j++) {
        Ans[i][j] = min(tAns[i][0] + h[rt][0][j] + C0[ls[rt]],
                        tAns[i][1] + h[rt][1][j] + C1[ls[rt]]);
      }
    return;
  }
  long long mid = (l + r) >> 1;
  if (L <= mid) Query(rt << 1, l, mid, L, R);
  if (R > mid) Query(rt << 1 | 1, mid + 1, r, L, R);
  return;
}
int main() {
  N = read();
  for (long long i = 1; i <= N; i++) w[i] = read();
  for (long long i = 1; i < N; i++) {
    long long u = read(), v = read(), w1 = read(), w2 = read();
    swap(w1, w2);
    insert(u, v, w1, w2);
    insert(v, u, w1, w2);
  }
  dfs(1, 0);
  dfs2(1, 1);
  dfs3(1, 0, INF);
  for (long long i = 1; i <= N; i++) {
    long long sz = vec[i].size();
    for (long long d = 0; d < 2; d++) {
      g[d] = 0;
      g[d ^ 1] = INF;
      for (long long j = 0, sz = vec[i].size(); j < sz; j++) {
        long long g0, g1;
        g[0] = g[0] + C0[vec[i][j]];
        g[1] = g[1] + C1[vec[i][j]];
        g0 = min(g[0], g[1] + w[vec[i][j]]);
        g1 = min(g[1], g[0] + w[vec[i][j]]);
        g[0] = g0;
        g[1] = g1;
        f[vec[i][j]][d][0] = g[0];
        f[vec[i][j]][d][1] = g[1];
      }
    }
  }
  build(1, 1, N);
  long long Q = read();
  while (Q--) {
    long long u = read(), v = read();
    memset(Ans, 0, sizeof(Ans));
    ug[0] = vg[0] = ug[1] = vg[1] = INF;
    ug[u & 1] = 0;
    vg[v & 1] = 0;
    u = (u + 1) / 2;
    v = (v + 1) / 2;
    while (top[u] != top[v]) {
      if (dep[top[u]] > dep[top[v]]) {
        for (long long i = 0; i < 2; i++)
          tmp[i] = min(ug[0] + f[u][i][0], ug[1] + f[u][i][1]);
        ug[0] = tmp[0];
        ug[1] = tmp[1];
        u = fa[top[u]];
      } else {
        for (long long i = 0; i < 2; i++)
          tmp[i] = min(vg[0] + f[v][i][0], vg[1] + f[v][i][1]);
        vg[0] = tmp[0];
        vg[1] = tmp[1];
        v = fa[top[v]];
      }
    }
    long long tu = u, tv = v;
    if (dfn[tu] > dfn[tv]) swap(tu, tv), swap(ug[0], vg[0]), swap(ug[1], vg[1]);
    Query(1, 1, N, dfn[tu], dfn[tv]);
    long long ans = INF;
    for (long long i = 0; i < 2; i++)
      for (long long j = 0; j < 2; j++) {
        ans = min(ans, Ans[i][j] + ug[i] + vg[j]);
      }
    printf("%lld\n", ans);
  }
}