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 + 7;
const int inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1000000007;
const double eps = 1e-13;
const double PI = acos(-1);
int n, q, depth[N];
long long d[N], gg[N], dp[N][2][2][20];
int f[N][20];
vector<pair<int, pair<long long, long long>>> G[N];
vector<pair<long long, int>> E[N];
void dfs(int u, int fa, pair<long long, long long> dis) {
  depth[u] = depth[fa] + 1;
  if (u > 1) {
    f[u][0] = fa;
    dp[u][0][0][0] = min(dis.first, dis.second + d[u] + d[fa]);
    dp[u][1][1][0] = min(dis.second, dis.first + d[u] + d[fa]);
    dp[u][0][1][0] = min(dis.first + d[fa], dis.second + d[u]);
    dp[u][1][0][0] = min(dis.second + d[fa], dis.first + d[u]);
    for (int i = 1; i < 20; i++) f[u][i] = f[f[u][i - 1]][i - 1];
    for (int i = 1; i < 20; i++) {
      int v = f[u][i - 1];
      dp[u][0][0][i] = min(dp[u][0][0][i - 1] + dp[v][0][0][i - 1],
                           dp[u][0][1][i - 1] + dp[v][1][0][i - 1]);
      dp[u][1][1][i] = min(dp[u][1][1][i - 1] + dp[v][1][1][i - 1],
                           dp[u][1][0][i - 1] + dp[v][0][1][i - 1]);
      dp[u][0][1][i] = min(dp[u][0][0][i - 1] + dp[v][0][1][i - 1],
                           dp[u][0][1][i - 1] + dp[v][1][1][i - 1]);
      dp[u][1][0][i] = min(dp[u][1][1][i - 1] + dp[v][1][0][i - 1],
                           dp[u][1][0][i - 1] + dp[v][0][0][i - 1]);
    }
  }
  for (auto& e : G[u]) {
    if (e.first == fa) continue;
    dfs(e.first, u, e.second);
  }
}
int getLca(int u, int v) {
  if (depth[u] < depth[v]) swap(u, v);
  for (int i = 19; i >= 0; i--)
    if (depth[f[u][i]] >= depth[v]) u = f[u][i];
  if (u == v) return u;
  for (int i = 19; i >= 0; i--)
    if (f[u][i] != f[v][i]) u = f[u][i], v = f[v][i];
  return f[u][0];
}
pair<long long, long long> calc(int u, int op1, int v) {
  int dis = depth[u] - depth[v];
  long long g[2], tmp[2];
  g[op1] = 0;
  g[op1 ^ 1] = d[u];
  for (int i = 19; i >= 0; i--) {
    if (dis >> i & 1) {
      tmp[0] = g[0], tmp[1] = g[1];
      g[0] = min(tmp[0] + dp[u][0][0][i], tmp[1] + dp[u][1][0][i]);
      g[1] = min(tmp[1] + dp[u][1][1][i], tmp[0] + dp[u][0][1][i]);
      u = f[u][i];
    }
  }
  return make_pair(g[0], g[1]);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%lld", &d[i]);
  for (int i = 2; i <= n; i++) {
    int u, v;
    long long w1, w2;
    scanf("%d%d%lld%lld", &u, &v, &w1, &w2);
    G[u].push_back(make_pair(v, make_pair(w1, w2)));
    G[v].push_back(make_pair(u, make_pair(w1, w2)));
    E[u].push_back(make_pair(w1 + w2, v));
    E[v].push_back(make_pair(w1 + w2, u));
  }
  priority_queue<pair<long long, int>, vector<pair<long long, int>>,
                 greater<pair<long long, int>>>
      que;
  for (int i = 1; i <= n; i++) {
    gg[i] = d[i];
    que.push(make_pair(d[i], i));
  }
  while (!que.empty()) {
    int u = que.top().second;
    long long val = que.top().first;
    que.pop();
    if (val > gg[u]) continue;
    for (auto& e : E[u]) {
      if (gg[e.second] > val + e.first) {
        gg[e.second] = val + e.first;
        que.push(make_pair(gg[e.second], e.second));
      }
    }
  }
  for (int i = 1; i <= n; i++) d[i] = gg[i];
  dfs(1, 0, make_pair(0, 0));
  scanf("%d", &q);
  while (q--) {
    int u, v;
    scanf("%d%d", &u, &v);
    int op1 = (u & 1) ? 0 : 1;
    int op2 = (v & 1) ? 0 : 1;
    if (u & 1)
      u = (u + 1) >> 1;
    else
      u >>= 1;
    if (v & 1)
      v = (v + 1) >> 1;
    else
      v >>= 1;
    int Lca = getLca(u, v);
    pair<long long, long long> disu = calc(u, op1, Lca);
    pair<long long, long long> disv = calc(v, op2, Lca);
    printf("%lld\n", min(disu.first + disv.first, disu.second + disv.second));
  }
  return 0;
}