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 + 5;
const long long inf = 1e18;
int n, q, cnt, hd[N], fa[19][N], dep[N];
long long a[N], d[N];
bool vis[N];
struct edge {
  int tt, nxt;
  long long w0, w1;
} e[N << 1];
struct node {
  long long s[2][2];
} mn[19][N];
priority_queue<pair<long long, int> > Q;
void addedge(int u, int v, long long w0, long long w1) {
  e[++cnt] = (edge){v, hd[u], w0, w1}, hd[u] = cnt;
}
node mg(node a, node b) {
  node c;
  c.s[0][0] = min(a.s[0][0] + b.s[0][0], a.s[0][1] + b.s[1][0]);
  c.s[0][1] = min(a.s[0][0] + b.s[0][1], a.s[0][1] + b.s[1][1]);
  c.s[1][0] = min(a.s[1][0] + b.s[0][0], a.s[1][1] + b.s[1][0]);
  c.s[1][1] = min(a.s[1][0] + b.s[0][1], a.s[1][1] + b.s[1][1]);
  return c;
}
void dijkstra() {
  for (int i = (1); i <= (n); ++i) d[i] = a[i], Q.push(make_pair(-d[i], i));
  while (!Q.empty()) {
    int x = Q.top().second;
    Q.pop();
    if (vis[x]) continue;
    vis[x] = 1;
    for (int i = hd[x]; i; i = e[i].nxt) {
      int v = e[i].tt;
      if (d[v] > d[x] + e[i].w1 + e[i].w0)
        d[v] = d[x] + e[i].w1 + e[i].w0, Q.push(make_pair(-d[v], v));
    }
  }
}
void dfs(int x) {
  dep[x] = dep[fa[0][x]] + 1;
  for (int j = (1); j <= (18); ++j) {
    fa[j][x] = fa[j - 1][fa[j - 1][x]];
    if (fa[j][x]) mn[j][x] = mg(mn[j - 1][x], mn[j - 1][fa[j - 1][x]]);
  }
  for (int i = hd[x]; i; i = e[i].nxt) {
    int v = e[i].tt;
    if (!dep[v]) {
      node c = mg((node){0, d[v], d[v], 0}, (node){e[i].w0, inf, inf, e[i].w1});
      mn[0][v] = mg(c, (node){0, d[x], d[x], 0});
      fa[0][v] = x, dfs(v);
    }
  }
}
node qpath(int u, int v) {
  bool ty = 0;
  if (dep[u] < dep[v]) swap(u, v), ty = 1;
  node res1 = (node){0, d[u], d[u], 0}, res2 = (node){0, d[v], d[v], 0};
  for (int j = (18); j >= (0); --j)
    if (dep[u] - dep[v] >= (1 << j)) res1 = mg(res1, mn[j][u]), u = fa[j][u];
  if (u == v) {
    if (ty) swap(res1.s[0][1], res1.s[1][0]);
    return res1;
  }
  for (int j = (18); j >= (0); --j)
    if (fa[j][u] != fa[j][v]) {
      res1 = mg(res1, mn[j][u]), res2 = mg(res2, mn[j][v]);
      u = fa[j][u], v = fa[j][v];
    }
  res1 = mg(res1, mn[0][u]), res2 = mg(res2, mn[0][v]);
  swap(res2.s[0][1], res2.s[1][0]);
  node res = mg(res1, res2);
  if (ty) swap(res.s[0][1], res.s[1][0]);
  return res;
}
int main() {
  scanf("%d", &n);
  for (int i = (1); i <= (n); ++i) scanf("%lld", &a[i]);
  for (int i = (1); i <= (n - 1); ++i) {
    int u, v;
    long long w0, w1;
    scanf("%d%d%lld%lld", &u, &v, &w1, &w0);
    addedge(u, v, w0, w1), addedge(v, u, w0, w1);
  }
  dijkstra(), dfs(1);
  scanf("%d", &q);
  while (q--) {
    int u, v;
    scanf("%d%d", &u, &v);
    printf("%lld\n", qpath((u + 1) >> 1, (v + 1) >> 1).s[u & 1][v & 1]);
  }
  return 0;
}