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;
char buf[1 << 21], *S = buf, *T = buf;
inline long long read() {
  long long a = 0;
  int c =
      ((S == T && (S = buf, T = buf + fread(buf, 1, 1 << 21, stdin), S == T))
           ? EOF
           : *(S++));
  for (; c < '0' || c > '9';
       c = ((S == T &&
             (S = buf, T = buf + fread(buf, 1, 1 << 21, stdin), S == T))
                ? EOF
                : *(S++)))
    ;
  for (; c >= '0' && c <= '9';
       c = ((S == T &&
             (S = buf, T = buf + fread(buf, 1, 1 << 21, stdin), S == T))
                ? EOF
                : *(S++)))
    a = (a << 1) + (a << 3) + (c ^ '0');
  return a;
}
struct edge {
  int v;
  long long w1, w2;
  int nxt;
  edge() {}
  edge(int _v, long long W1, long long W2, int next)
      : v(_v), w1(W1), w2(W2), nxt(next) {}
} e[600010];
int head[300010], tot, dep[300010];
int f[300010][20];
long long c[300010][20][2][2];
long long w[300010];
inline void addedge(int u, int v, long long w1, long long w2) {
  e[++tot] = edge(v, w1, w2, head[u]);
  head[u] = tot;
}
inline void dp1(int now, int f) {
  for (int i = head[now]; i; i = e[i].nxt) {
    if (e[i].v == f) continue;
    dp1(e[i].v, now);
    w[now] = min(w[now], w[e[i].v] + e[i].w1 + e[i].w2);
  }
}
inline void dp2(int now, int f) {
  for (int i = head[now]; i; i = e[i].nxt) {
    if (e[i].v == f) continue;
    w[e[i].v] = min(w[e[i].v], w[now] + e[i].w1 + e[i].w2);
    dp2(e[i].v, now);
  }
}
inline void dfs(int now, int fa) {
  dep[now] = dep[fa] + 1;
  for (int i = head[now]; i; i = e[i].nxt) {
    if (e[i].v == fa) continue;
    f[e[i].v][0] = now;
    c[e[i].v][0][0][0] = min(e[i].w2, e[i].w1 + w[now] + w[e[i].v]);
    c[e[i].v][0][0][1] = min(e[i].w1 + w[e[i].v], e[i].w2 + w[now]);
    c[e[i].v][0][1][0] = min(e[i].w2 + w[e[i].v], e[i].w1 + w[now]);
    c[e[i].v][0][1][1] = min(e[i].w1, e[i].w2 + w[now] + w[e[i].v]);
    dfs(e[i].v, now);
  }
}
int n, q;
inline void ready() {
  for (int j = 1; j < 20; j++)
    for (int i = 1; i <= n; i++)
      f[i][j] = f[f[i][j - 1]][j - 1],
      c[i][j][0][0] = min(c[i][j - 1][0][0] + c[f[i][j - 1]][j - 1][0][0],
                          c[i][j - 1][0][1] + c[f[i][j - 1]][j - 1][1][0]),
      c[i][j][1][0] = min(c[i][j - 1][1][0] + c[f[i][j - 1]][j - 1][0][0],
                          c[i][j - 1][1][1] + c[f[i][j - 1]][j - 1][1][0]),
      c[i][j][0][1] = min(c[i][j - 1][0][0] + c[f[i][j - 1]][j - 1][0][1],
                          c[i][j - 1][0][1] + c[f[i][j - 1]][j - 1][1][1]),
      c[i][j][1][1] = min(c[i][j - 1][1][0] + c[f[i][j - 1]][j - 1][0][1],
                          c[i][j - 1][1][1] + c[f[i][j - 1]][j - 1][1][1]);
}
inline long long get(int a, int typea, int b, int typeb) {
  if (dep[a] < dep[b]) swap(a, b), swap(typea, typeb);
  long long a0 = typea ? w[a] : 0, b0 = typeb ? w[b] : 0;
  long long a1 = w[a] - a0, b1 = w[b] - b0, new0, new1;
  for (int i = 19; i >= 0; i--)
    if (dep[f[a][i]] >= dep[b]) {
      new0 = min(a0 + c[a][i][0][0], a1 + c[a][i][1][0]),
      new1 = min(a0 + c[a][i][0][1], a1 + c[a][i][1][1]);
      a0 = new0, a1 = new1;
      a = f[a][i];
    }
  if (a == b) return min(a0 + b0, a1 + b1);
  for (int i = 19; i >= 0; i--)
    if (f[a][i] != f[b][i]) {
      new0 = min(a0 + c[a][i][0][0], a1 + c[a][i][1][0]);
      new1 = min(a0 + c[a][i][0][1], a1 + c[a][i][1][1]);
      a0 = new0, a1 = new1;
      a = f[a][i];
      new0 = min(b0 + c[b][i][0][0], b1 + c[b][i][1][0]);
      new1 = min(b0 + c[b][i][0][1], b1 + c[b][i][1][1]);
      b0 = new0, b1 = new1;
      b = f[b][i];
    }
  new0 = min(a0 + c[a][0][0][0], a1 + c[a][0][1][0]),
  new1 = min(a0 + c[a][0][0][1], a1 + c[a][0][1][1]);
  a0 = new0, a1 = new1;
  a = f[a][0];
  new0 = min(b0 + c[b][0][0][0], b1 + c[b][0][1][0]),
  new1 = min(b0 + c[b][0][0][1], b1 + c[b][0][1][1]);
  b0 = new0, b1 = new1;
  b = f[b][0];
  return min(a0 + b0, a1 + b1);
}
long long u, v, w1, w2;
int main() {
  n = read();
  for (int i = 1; i <= n; i++) w[i] = read();
  for (int i = 1; i < n; i++)
    u = read(), v = read(), w1 = read(), w2 = read(), addedge(u, v, w1, w2),
    addedge(v, u, w1, w2);
  dp1(1, 0);
  dp2(1, 0);
  dfs(1, 0);
  ready();
  q = read();
  for (int i = 1; i <= q; i++) {
    u = read(), v = read();
    printf("%lld\n", get((u + 1) >> 1, u & 1, (v + 1) >> 1, v & 1));
  }
  return 0;
}