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 = 300005;
const long long inf = 1000000000000000000ll;
int n, m, i, j, s = 0, u, v, Q, k;
long long d[N], w1, w2;
int head[N], Next[N * 2], adj[N * 2], vis[N], fa[N], son[N], dep[N];
int top[N], num[N], siz[N];
long long leng1[N * 2], leng2[N * 2];
struct str {
  long long d;
  int x;
};
bool operator<(str a, str b) { return a.d > b.d; }
priority_queue<str> q;
struct mt {
  long long a[2][2];
} t[N], tree[N * 4];
mt mult(mt a, mt b) {
  mt t;
  t.a[0][0] = min(a.a[0][0] + b.a[0][0], a.a[0][1] + b.a[1][0]);
  t.a[0][1] = min(a.a[0][0] + b.a[0][1], a.a[0][1] + b.a[1][1]);
  t.a[1][0] = min(a.a[1][0] + b.a[0][0], a.a[1][1] + b.a[1][0]);
  t.a[1][1] = min(a.a[1][0] + b.a[0][1], a.a[1][1] + b.a[1][1]);
  return t;
}
void Push(int u, int v, long long w1, long long w2) {
  Next[++k] = head[u];
  head[u] = k;
  adj[k] = v;
  leng1[k] = w1;
  leng2[k] = w2;
}
mt Query(int i, int l, int r, int ll, int rr) {
  if (l >= ll && r <= rr) return tree[i];
  int mid = l + r >> 1;
  if (mid >= ll && mid < rr)
    return mult(Query(i << 1 | 1, mid + 1, r, ll, rr),
                Query(i << 1, l, mid, ll, rr));
  else if (mid >= ll)
    return Query(i << 1, l, mid, ll, rr);
  else
    return Query(i << 1 | 1, mid + 1, r, ll, rr);
}
void dfs(int i, int f) {
  int j;
  fa[i] = f;
  siz[i] = 1;
  for (j = head[i]; j; j = Next[j])
    if (adj[j] != f) {
      dep[adj[j]] = dep[i] + 1;
      dfs(adj[j], i);
      siz[i] += siz[adj[j]];
      if (siz[adj[j]] > siz[son[i]]) son[i] = adj[j];
    }
}
void dfs2(int i, int t) {
  int j;
  top[i] = t;
  num[i] = ++k;
  if (son[i]) dfs2(son[i], t);
  for (j = head[i]; j; j = Next[j])
    if (adj[j] != fa[i] && adj[j] != son[i]) dfs2(adj[j], adj[j]);
}
void Build(int i, int l, int r) {
  if (l == r) {
    tree[i] = t[l];
    return;
  }
  int mid = l + r >> 1;
  Build(i << 1, l, mid);
  Build(i << 1 | 1, mid + 1, r);
  tree[i] = mult(tree[i << 1 | 1], tree[i << 1]);
}
int LCA(int u, int v) {
  while (top[u] != top[v]) {
    if (dep[top[u]] < dep[top[v]]) swap(u, v);
    u = top[u];
    u = fa[u];
  }
  return (dep[u] < dep[v] ? u : v);
}
mt Ans(int u, int v) {
  mt ans;
  ans.a[1][0] = ans.a[0][1] = inf;
  ans.a[0][0] = ans.a[1][1] = 0;
  while (top[u] != top[v]) {
    ans = mult(ans, Query(1, 1, n, num[top[u]], num[u]));
    u = top[u];
    u = fa[u];
  }
  if (u != v) ans = mult(ans, Query(1, 1, n, num[v] + 1, num[u]));
  return ans;
}
int main() {
  scanf("%d", &n);
  for (i = 1; i <= n; ++i) {
    scanf("%lld", &d[i]);
    q.push((str){d[i], i});
  }
  for (i = 1; i < n; ++i) {
    scanf("%d %d %lld %lld", &u, &v, &w1, &w2);
    Push(u, v, w1, w2);
    Push(v, u, w1, w2);
  }
  while (!q.empty()) {
    str x = q.top();
    q.pop();
    if (vis[x.x]) continue;
    vis[x.x] = 1;
    for (i = head[x.x]; i; i = Next[i])
      if (d[adj[i]] > d[x.x] + leng1[i] + leng2[i]) {
        d[adj[i]] = d[x.x] + leng1[i] + leng2[i];
        q.push((str){d[adj[i]], adj[i]});
      }
  }
  k = 0;
  dfs(1, 0);
  dfs2(1, 1);
  for (i = 1; i <= n; ++i)
    for (j = head[i]; j; j = Next[j])
      if (adj[j] != fa[i]) {
        t[num[adj[j]]].a[0][0] = leng1[j];
        t[num[adj[j]]].a[0][1] = leng1[j] + d[i];
        t[num[adj[j]]].a[1][0] = leng2[j] + d[i];
        t[num[adj[j]]].a[1][1] = leng2[j];
      }
  Build(1, 1, n);
  scanf("%d", &Q);
  while (Q--) {
    scanf("%d %d", &u, &v);
    long long p, q, x, y;
    if (u & 1) {
      p = 0;
      q = d[(u + 1) / 2];
    } else {
      p = d[(u + 1) / 2];
      q = 0;
    }
    if (v & 1) {
      x = 0;
      y = d[(v + 1) / 2];
    } else {
      x = d[(v + 1) / 2];
      y = 0;
    }
    u = (u + 1) / 2, v = (v + 1) / 2;
    int lca = LCA(u, v);
    mt a = Ans(u, lca);
    mt b = Ans(v, lca);
    long long l = min(p + a.a[0][0], q + a.a[1][0]),
              r = min(p + a.a[0][1], q + a.a[1][1]);
    long long g = min(x + b.a[0][0], y + b.a[1][0]),
              f = min(x + b.a[0][1], y + b.a[1][1]);
    printf("%lld\n", min(l + g, r + f));
  }
}