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;
int n, f[300005][19], d[300005];
long long a[300005][2], b[300005], dp[300005][19][2][2];
vector<int> v[300005];
vector<long long> e1[300005], e2[300005];
void dfs(int x, int y) {
  d[x] = d[y] + 1, f[x][0] = y;
  for (int i = 0; i < 18; ++i) f[x][i + 1] = f[f[x][i]][i];
  for (int i = 0; i < v[x].size(); ++i) {
    if (v[x][i] == y)
      a[x][0] = e1[x][i], a[x][1] = e2[x][i];
    else
      dfs(v[x][i], x);
  }
}
void upd(int x, int y) {
  for (int i = 0; i < v[x].size(); ++i) {
    if (v[x][i] == y) continue;
    upd(v[x][i], x);
    b[x] = min(b[x], e1[x][i] + b[v[x][i]] + e2[x][i]);
  }
}
void upd2(int x, int y) {
  for (int i = 0; i < v[x].size(); ++i) {
    if (v[x][i] == y) continue;
    b[v[x][i]] = min(b[v[x][i]], e1[x][i] + b[x] + e2[x][i]);
    upd2(v[x][i], x);
  }
}
void ope(int x, int y) {
  dp[x][0][0][0] = min(a[x][0], b[x] + a[x][1] + b[y]);
  dp[x][0][0][1] = min(a[x][0] + b[y], b[x] + a[x][1]);
  dp[x][0][1][0] = min(a[x][1] + b[y], b[x] + a[x][0]);
  dp[x][0][1][1] = min(a[x][1], b[x] + a[x][0] + b[y]);
  for (int i = 0; i < 18; ++i) {
    int _ = f[x][i];
    dp[x][i + 1][0][0] =
        min(dp[x][i][0][0] + dp[_][i][0][0], dp[x][i][0][1] + dp[_][i][1][0]);
    dp[x][i + 1][0][1] =
        min(dp[x][i][0][0] + dp[_][i][0][1], dp[x][i][0][1] + dp[_][i][1][1]);
    dp[x][i + 1][1][0] =
        min(dp[x][i][1][0] + dp[_][i][0][0], dp[x][i][1][1] + dp[_][i][1][0]);
    dp[x][i + 1][1][1] =
        min(dp[x][i][1][0] + dp[_][i][0][1], dp[x][i][1][1] + dp[_][i][1][1]);
  }
  for (int i = 0; i < v[x].size(); ++i)
    if (v[x][i] != y) ope(v[x][i], x);
}
int lca(int x, int y) {
  if (d[x] < d[y]) swap(x, y);
  for (int i = 18; i >= 0; --i)
    if (d[f[x][i]] >= d[y]) x = f[x][i];
  if (x == y) return x;
  for (int i = 18; i >= 0; --i)
    if (f[x][i] != f[y][i]) x = f[x][i], y = f[y][i];
  return f[x][0];
}
pair<long long, long long> up(int x, int y, int z) {
  long long res[2] = {0, 0};
  res[z ^ 1] = b[x];
  for (int i = 18; i >= 0; --i) {
    if (d[f[x][i]] < d[y]) continue;
    long long X, Y;
    X = min(res[0] + dp[x][i][0][0], res[1] + dp[x][i][1][0]);
    Y = min(res[0] + dp[x][i][0][1], res[1] + dp[x][i][1][1]);
    res[0] = X, res[1] = Y, x = f[x][i];
  }
  return make_pair(res[0], res[1]);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%I64d", b + i);
  for (int i = 1; i < n; ++i) {
    int x, y;
    long long p, q;
    scanf("%d%d%I64d%I64d", &x, &y, &p, &q);
    v[x].push_back(y), v[y].push_back(x), e1[x].push_back(p),
        e1[y].push_back(p), e2[x].push_back(q), e2[y].push_back(q);
  }
  dfs(1, 0);
  upd(1, 0);
  upd2(1, 0);
  ope(1, 0);
  int T;
  scanf("%d", &T);
  while (T--) {
    int x, y, z, X, Y;
    scanf("%d%d", &x, &y);
    if (x & 1)
      X = 0;
    else
      X = 1;
    if (y & 1)
      Y = 0;
    else
      Y = 1;
    x = (x + 1) >> 1, y = (y + 1) >> 1;
    z = lca(x, y);
    pair<long long, long long> xx = up(x, z, X), yy = up(y, z, Y);
    long long ans;
    ans = min(xx.first + yy.first, xx.second + yy.second);
    printf("%I64d\n", ans);
  }
  return 0;
}