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>
const int M = 300005;
const long long INF = 1e18;
using namespace std;
inline long long read() {
  char c = getchar();
  long long x = 0, w = 1;
  while (c > '9' || c < '0') {
    if (c == '-') w = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = x * 10 + c - '0';
    c = getchar();
  }
  return x * w;
}
int n, lg[M], dep[M];
long long w[M], st[M][22], st1[M][22][2][2], dp1[2], dp2[2];
struct Node {
  int v;
  long long w1, w2;
};
vector<Node> vec[M];
void dfs1(int u, int father) {
  long long w1, w2;
  st[u][0] = father;
  dep[u] = dep[father] + 1;
  for (int i = 0, v; i < vec[u].size(); i++) {
    v = vec[u][i].v, w1 = vec[u][i].w1, w2 = vec[u][i].w2;
    if (v == father) continue;
    dfs1(v, u);
    w[u] = min(w[u], w[v] + w1 + w2);
  }
}
void dfs2(int u, int father) {
  long long w1, w2;
  for (int i = 0, v; i < vec[u].size(); i++) {
    v = vec[u][i].v, w1 = vec[u][i].w1, w2 = vec[u][i].w2;
    if (v == father) continue;
    w[v] = min(w[v], w[u] + w1 + w2);
    dfs2(v, u);
  }
}
void dfs(int u, int father) {
  long long w1, w2;
  for (int i = 0, v; i < vec[u].size(); i++) {
    v = vec[u][i].v, w1 = vec[u][i].w1, w2 = vec[u][i].w2;
    if (v == father) continue;
    dfs(v, u);
    st1[v][0][0][0] = min(w1, w[v] + w2 + w[u]);
    st1[v][0][1][1] = min(w2, w[u] + w1 + w[v]);
    st1[v][0][0][1] = min(w[v] + w2, w1 + w[u]);
    st1[v][0][1][0] = min(w2 + w[u], w[v] + w1);
  }
}
inline int LCA(int u, int v) {
  if (dep[u] < dep[v]) swap(u, v);
  for (int i = lg[n]; i >= 0; i--)
    if (dep[st[u][i]] >= dep[v]) u = st[u][i];
  if (u == v) return u;
  for (int i = lg[n]; i >= 0; i--)
    if (st[u][i] != st[v][i]) u = st[u][i], v = st[v][i];
  return st[u][0];
}
inline long long Solve(int x, int y) {
  int u = ((x + 1) >> 1), v = ((y + 1) >> 1), lcap;
  if (dep[u] < dep[v]) {
    swap(u, v);
    swap(x, y);
  }
  lcap = LCA(u, v);
  long long tp0, tp1;
  dp1[(x + 1) & 1] = 0;
  dp1[((x + 1) & 1) ^ 1] = w[u];
  for (int i = lg[n]; i >= 0; i--) {
    if (dep[st[u][i]] >= dep[lcap]) {
      tp0 = dp1[0];
      tp1 = dp1[1];
      dp1[0] = min(tp0 + st1[u][i][0][0], tp1 + st1[u][i][1][0]);
      dp1[1] = min(tp0 + st1[u][i][0][1], tp1 + st1[u][i][1][1]);
      u = st[u][i];
    }
  }
  u = v;
  dp2[(y + 1) & 1] = 0;
  dp2[((y + 1) & 1) ^ 1] = w[u];
  for (int i = lg[n]; i >= 0; i--) {
    if (dep[st[u][i]] >= dep[lcap]) {
      tp0 = dp2[0], tp1 = dp2[1];
      dp2[0] = min(tp0 + st1[u][i][0][0], tp1 + st1[u][i][1][0]);
      dp2[1] = min(tp0 + st1[u][i][0][1], tp1 + st1[u][i][1][1]);
      u = st[u][i];
    }
  }
  return min(dp1[0] + dp2[0], dp1[1] + dp2[1]);
}
int main() {
  n = read();
  for (int i = 2; i <= n; i++) lg[i] = lg[i >> 1] + 1;
  for (int i = 1; i <= n; i++) w[i] = read();
  long long w1, w2;
  for (int i = 1, u, v; i < n; i++) {
    u = read();
    v = read();
    w1 = read();
    w2 = read();
    vec[u].push_back((Node){v, w1, w2});
    vec[v].push_back((Node){u, w1, w2});
  }
  memset(st1, 31, sizeof(st1));
  dfs1(1, 0);
  dfs2(1, 0);
  dfs(1, 0);
  for (int j = 1; j <= lg[n]; j++)
    for (int u = 1; u <= n; u++) {
      st[u][j] = st[st[u][j - 1]][j - 1];
      st[u][j] = st[st[u][j - 1]][j - 1];
      st1[u][j][0][0] =
          min(st1[u][j - 1][0][0] + st1[st[u][j - 1]][j - 1][0][0],
              st1[u][j - 1][0][1] + st1[st[u][j - 1]][j - 1][1][0]);
      st1[u][j][0][1] =
          min(st1[u][j - 1][0][0] + st1[st[u][j - 1]][j - 1][0][1],
              st1[u][j - 1][0][1] + st1[st[u][j - 1]][j - 1][1][1]);
      st1[u][j][1][0] =
          min(st1[u][j - 1][1][0] + st1[st[u][j - 1]][j - 1][0][0],
              st1[u][j - 1][1][1] + st1[st[u][j - 1]][j - 1][1][0]);
      st1[u][j][1][1] =
          min(st1[u][j - 1][1][0] + st1[st[u][j - 1]][j - 1][0][1],
              st1[u][j - 1][1][1] + st1[st[u][j - 1]][j - 1][1][1]);
    }
  int Q = read(), x, y;
  while (Q--) {
    x = read();
    y = read();
    printf("%lld\n", Solve(x, y));
  }
  return 0;
}