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;
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
const int MAXN = 300000;
const int MAXQ = 600000;
const int MAXLVL = 18;
int n;
long long crosscost[MAXN];
long long treecost[MAXN - 1][2];
vector<pair<int, int>> adj[MAXN];
int nq;
int qa[MAXQ], qb[MAXQ];
long long qans[MAXQ];
priority_queue<pair<long long, int>> pq;
long long reducedcost[MAXN];
int sz[MAXN];
bool alive[MAXN];
int cent[MAXN][MAXLVL + 1];
long long dp[MAXN][MAXLVL + 1][2][2];
void dfsprocess(int at, int par, int parid, int lvl, int c) {
  cent[at][lvl] = c;
  if (parid != -1)
    for (int a = (0); a < (2); ++a)
      for (int b = (0); b < (2); ++b)
        dp[at][lvl][a][b] = min(
            treecost[parid][a] + dp[par][lvl][a][b],
            reducedcost[at] + treecost[parid][1 - a] + dp[par][lvl][1 - a][b]);
  for (int i = (0); i < (((int)(adj[at]).size())); ++i) {
    int to = adj[at][i].first, id = adj[at][i].second;
    if (to == par || !alive[to]) continue;
    dfsprocess(to, at, id, lvl, c);
  }
}
void process(int c, int lvl) {
  for (int a = (0); a < (2); ++a)
    for (int b = (0); b < (2); ++b)
      dp[c][lvl][a][b] = a == b ? 0 : reducedcost[c];
  dfsprocess(c, -1, -1, lvl, c);
}
void dfssz(int at, int par) {
  sz[at] = 1;
  for (int i = (0); i < (((int)(adj[at]).size())); ++i) {
    int to = adj[at][i].first;
    if (to == par || !alive[to]) continue;
    dfssz(to, at);
    sz[at] += sz[to];
  }
}
int dfscent(int at, int par, int totsz) {
  for (int i = (0); i < (((int)(adj[at]).size())); ++i) {
    int to = adj[at][i].first;
    if (to == par || !alive[to]) continue;
    if (2 * sz[to] >= totsz) return dfscent(to, at, totsz);
  }
  return at;
}
int getcentroid(int root) {
  dfssz(root, -1);
  return dfscent(root, -1, sz[root]);
}
void decompose(int at, int lvl) {
  int c = getcentroid(at);
  process(c, lvl);
  alive[c] = false;
  for (int i = (0); i < (((int)(adj[c]).size())); ++i) {
    int to = adj[c][i].first;
    if (!alive[to]) continue;
    decompose(to, lvl + 1);
  }
}
void solve() {
  pq = priority_queue<pair<long long, int>>();
  for (int i = (0); i < (n); ++i)
    reducedcost[i] = crosscost[i], pq.push(make_pair(-reducedcost[i], i));
  while (!pq.empty()) {
    long long cost = -pq.top().first;
    int at = pq.top().second;
    pq.pop();
    if (reducedcost[at] != cost) continue;
    for (int i = (0); i < (((int)(adj[at]).size())); ++i) {
      int to = adj[at][i].first, id = adj[at][i].second;
      long long ncost = cost + treecost[id][0] + treecost[id][1];
      if (ncost < reducedcost[to])
        reducedcost[to] = ncost, pq.push(make_pair(-reducedcost[to], to));
    }
  }
  for (int i = (0); i < (n); ++i) alive[i] = true;
  memset(cent, -1, sizeof(cent));
  decompose(0, 0);
  for (int i = (0); i < (nq); ++i) {
    int a = qa[i] / 2, aside = qa[i] % 2, b = qb[i] / 2, bside = qb[i] % 2;
    int lvl = MAXLVL;
    while (lvl >= 0 && (cent[a][lvl] == -1 || cent[b][lvl] == -1 ||
                        cent[a][lvl] != cent[b][lvl]))
      --lvl;
    assert(lvl >= 0);
    qans[i] = min(dp[a][lvl][aside][0] + dp[b][lvl][bside][0],
                  dp[a][lvl][aside][1] + dp[b][lvl][bside][1]);
  }
}
void run() {
  scanf("%d", &n);
  for (int i = (0); i < (n); ++i) scanf("%lld", &crosscost[i]);
  for (int i = (0); i < (n - 1); ++i) {
    int a, b;
    scanf("%d%d%lld%lld", &a, &b, &treecost[i][0], &treecost[i][1]);
    --a, --b;
    adj[a].push_back(make_pair(b, i));
    adj[b].push_back(make_pair(a, i));
  }
  scanf("%d", &nq);
  for (int i = (0); i < (nq); ++i)
    scanf("%d%d", &qa[i], &qb[i]), --qa[i], --qb[i];
  solve();
  for (int i = (0); i < (nq); ++i) printf("%lld\n", qans[i]);
}
int main() {
  run();
  return 0;
}