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;
vector<long long> adj[700000], wei[700000];
long long we[700000], n, q, sz[700000], dis[700000];
bool dead[700000];
void calc(long long u, long long p) {
  sz[u] = 1;
  for (long long v : adj[u])
    if (v - p && !dead[v]) {
      calc(v, u);
      sz[u] += sz[v];
    }
}
long long centroid(long long u, long long p, long long r) {
  for (long long v : adj[u])
    if (v - p && !dead[v])
      if (sz[v] > r) return centroid(v, u, r);
  return u;
}
long long inf = 1e18;
unordered_map<long long, long long> distanc[700000];
void updatedis(long long u, long long p) {
  dis[2 * u - 1] = inf;
  dis[2 * u] = inf;
  for (long long v : adj[u])
    if (v - p && !dead[v]) updatedis(v, u);
}
void printdis(long long u, long long p, long long r) {
  distanc[r][2 * u - 1] = dis[2 * u - 1];
  distanc[r][2 * u] = dis[2 * u];
  for (long long v : adj[u])
    if (v - p && !dead[v]) printdis(v, u, r);
}
void dijkstra(long long src) {
  priority_queue<pair<long long, long long> > pq;
  pq.push(make_pair(0, src));
  updatedis((src + 1) >> 1, -1);
  dis[src] = 0;
  while (!pq.empty()) {
    pair<long long, long long> node = pq.top();
    long long u = node.second;
    pq.pop();
    if (dis[u] < -node.first) continue;
    for (long long i = 0; i < adj[(u + 1) >> 1].size(); i++) {
      long long v = adj[(u + 1) >> 1][i];
      v = 2 * v - (u & 1);
      long long w = wei[(u + 1) >> 1][2 * i + 1 - (u & 1)];
      if (dis[u] + w < dis[v]) {
        dis[v] = dis[u] + w;
        pq.push(make_pair(-dis[v], v));
      }
    }
    long long v = u;
    if (u & 1)
      v++;
    else
      v--;
    long long w = we[(u + 1) >> 1];
    if (dis[u] + w < dis[v]) {
      dis[v] = dis[u] + w;
      pq.push(make_pair(-dis[v], v));
    }
  }
  printdis((src + 1) >> 1, -1, src);
}
long long cpar[700000], lvl[700000], in[700000], out[700000], _tm;
void decompose(long long u, long long p, long long lv) {
  calc(u, 0);
  long long c = centroid(u, p, sz[u] >> 1);
  dijkstra(2 * c - 1);
  dijkstra(2 * c);
  dead[c] = 1;
  cpar[c] = p;
  in[c] = ++_tm;
  lvl[c] = lv;
  for (long long v : adj[c])
    if (!dead[v]) decompose(v, c, 1 + lv);
  out[c] = ++_tm;
}
long long query(long long u, long long v, long long p, long long q) {
  if (lvl[u] > lvl[v]) swap(u, v);
  while (v && !(in[u] <= in[v] && out[v] <= out[u])) {
    v = cpar[v];
    if (lvl[u] > lvl[v]) swap(u, v);
  }
  if (v == 0) return -1;
  long long cur = u;
  long long ret = inf;
  while (cur > 0) {
    ret = min(ret, distanc[cur * 2][p] + distanc[cur * 2][q]);
    ret = min(ret, distanc[cur * 2 - 1][p] + distanc[cur * 2 - 1][q]);
    cur = cpar[cur];
  }
  return ret;
}
int main() {
  cin >> n;
  for (long long i = 1; i <= n; i++) scanf("%lld ", &we[i]);
  long long u, v, a, b;
  for (long long i = 1; i < n; i++) {
    scanf("%lld %lld %lld %lld", &u, &v, &a, &b);
    adj[u].push_back(v);
    wei[u].push_back(a);
    wei[u].push_back(b);
    adj[v].push_back(u);
    wei[v].push_back(a);
    wei[v].push_back(b);
  }
  decompose(1, 0, 0);
  cin >> q;
  for (long long i = 0; i < q; i++) {
    scanf("%lld %lld", &u, &v);
    printf("%lld\n", query((u + 1) / 2, (v + 1) / 2, u, v));
  }
  return 0;
}