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 = 300010, LOG = 20;
int n, dp[LOG][N], depth[N], u, v, l, q;
vector<pair<int, pair<long long, long long> > > g[N];
long long arr[N], cur[N][2], w1, w2, dp2[LOG][2][2][N], val[2], val2[2], ans;
bool A, B;
void DFS(int node) {
  for (int i = 0; i < (int)g[node].size(); i++) {
    if (g[node][i].first == dp[0][node]) continue;
    dp[0][g[node][i].first] = node;
    cur[g[node][i].first][0] = g[node][i].second.first;
    cur[g[node][i].first][1] = g[node][i].second.second;
    depth[g[node][i].first] = depth[node] + 1;
    DFS(g[node][i].first);
    arr[node] = min(arr[node], arr[g[node][i].first] + g[node][i].second.first +
                                   g[node][i].second.second);
  }
}
void DFS2(int node) {
  if (dp[0][node] != -1) {
    arr[node] = min(arr[node], arr[dp[0][node]] + cur[node][0] + cur[node][1]);
  }
  for (int i = 0; i < (int)g[node].size(); i++) {
    if (g[node][i].first == dp[0][node]) continue;
    DFS2(g[node][i].first);
  }
}
int LCA(int u, int v) {
  if (depth[u] > depth[v]) swap(u, v);
  for (int k = LOG - 1; k >= 0; k--) {
    if (depth[u] + (1 << k) <= depth[v]) v = dp[k][v];
  }
  if (u == v) return u;
  for (int k = LOG - 1; k >= 0; k--) {
    if (dp[k][u] != dp[k][v]) u = dp[k][u], v = dp[k][v];
  }
  return dp[0][u];
}
long long tmp1, tmp2;
void make(long long *val, int d, int u) {
  for (int k = LOG - 1; k >= 0; k--) {
    if ((1 << k) > d) continue;
    d -= (1 << k);
    tmp1 = min(val[0] + dp2[k][0][0][u], val[1] + dp2[k][1][0][u]);
    tmp2 = min(val[0] + dp2[k][0][1][u], val[1] + dp2[k][1][1][u]);
    val[0] = tmp1;
    val[1] = tmp2;
    u = dp[k][u];
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &arr[i]);
  }
  for (int i = 0; i < n - 1; i++) {
    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)));
  }
  dp[0][1] = -1;
  DFS(1);
  DFS2(1);
  for (int i = 2; i <= n; i++) {
    dp2[0][0][0][i] = min(cur[i][0], cur[i][1] + arr[i] + arr[dp[0][i]]);
    dp2[0][0][1][i] = min(cur[i][1] + arr[i], cur[i][0] + arr[dp[0][i]]);
    dp2[0][1][0][i] = min(cur[i][0] + arr[i], cur[i][1] + arr[dp[0][i]]);
    dp2[0][1][1][i] = min(cur[i][1], cur[i][0] + arr[i] + arr[dp[0][i]]);
  }
  for (int k = 1; k < LOG; k++) {
    for (int i = 1; i <= n; i++) {
      if (dp[k - 1][i] == -1) {
        dp[k][i] = -1;
        continue;
      }
      dp[k][i] = dp[k - 1][dp[k - 1][i]];
      for (int a = 0; a < 2; a++) {
        for (int b = 0; b < 2; b++) {
          dp2[k][a][b][i] =
              min(dp2[k - 1][a][0][i] + dp2[k - 1][0][b][dp[k - 1][i]],
                  dp2[k - 1][a][1][i] + dp2[k - 1][1][b][dp[k - 1][i]]);
        }
      }
    }
  }
  scanf("%d", &q);
  while (q--) {
    scanf("%d%d", &u, &v);
    A = ((u & 1) ^ 1);
    B = ((v & 1) ^ 1);
    u = (u + 1) / 2;
    v = (v + 1) / 2;
    if (u == v) {
      printf("%lld\n", arr[u]);
      continue;
    }
    l = LCA(u, v);
    val[A] = 0, val[A ^ 1] = arr[u];
    val2[B] = 0, val2[B ^ 1] = arr[v];
    make(val, depth[u] - depth[l], u);
    make(val2, depth[v] - depth[l], v);
    ans = min(val[0] + val2[0], val[1] + val2[1]);
    printf("%lld\n", ans);
  }
  return 0;
}