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 N;
signed long long OE[303030];
int X[303030], Y[303030];
signed long long OO[303030], EE[303030];
vector<pair<int, signed long long>> E[303030];
vector<pair<int, signed long long>> E2[603030];
signed long long D[303030];
signed long long D2[603030][2];
int Q;
signed long long U[606060], V[606060];
signed long long ret[606060];
int vis[301010], id[303030];
int NV[301010];
int dfs(int cur, int pre) {
  NV[cur] = 1;
  for (auto& e : E[cur])
    if (e.first != pre && vis[e.first] == 0) NV[cur] += dfs(e.first, cur);
  D2[cur * 2][0] = D2[cur * 2][1] = D2[cur * 2 + 1][0] = D2[cur * 2 + 1][1] =
      1LL << 60;
  return NV[cur];
}
int dfs2(int cur, int pre, int TNV) {
  int tot = 1;
  int ok = 1;
  for (auto& e : E[cur])
    if (e.first != pre && vis[e.first] == 0) {
      int c = dfs2(e.first, cur, TNV);
      if (c != -1) return c;
      tot += NV[e.first];
      if (NV[e.first] * 2 > TNV) ok = 0;
    }
  if ((TNV - tot) * 2 > TNV) ok = 0;
  if (ok) return cur;
  return -1;
}
void dfs3(int cur, int pre, int col) {
  id[cur] = col;
  for (auto& e : E[cur])
    if (e.first != pre && vis[e.first] == 0) dfs3(e.first, cur, col);
}
void split(int cur, vector<int>& C) {
  if (vis[cur] || C.empty()) return;
  int TNV = dfs(cur, -1);
  if (TNV == 0) return;
  int center = dfs2(cur, -1, TNV);
  vis[center] = 1;
  vector<vector<int>> cand(E[center].size());
  int i;
  for (i = 0; i < (E[center].size()); i++)
    if (vis[E[center][i].first] == 0) dfs3(E[center][i].first, center, i);
  id[center] = -1;
  D2[center * 2][0] = D2[center * 2 + 1][1] = 0;
  priority_queue<pair<signed long long, int>> PQ;
  PQ.push({0, center * 2 * 2});
  PQ.push({0, (center * 2 + 1) * 2 + 1});
  while (PQ.size()) {
    signed long long co = -PQ.top().first;
    int cur = PQ.top().second / 2;
    int t = PQ.top().second % 2;
    PQ.pop();
    if (D2[cur][t] != co) continue;
    for (auto& e : E2[cur])
      if (D2[e.first][t] > co + e.second) {
        D2[e.first][t] = co + e.second;
        PQ.push({-D2[e.first][t], e.first * 2 + t});
      }
  }
  for (auto& c : C) {
    if (id[U[c] / 2] == id[V[c] / 2] && id[U[c] / 2] != -1) {
      cand[id[U[c] / 2]].push_back(c);
    } else {
      ret[c] = min(D2[U[c]][0] + D2[V[c]][0], D2[U[c]][1] + D2[V[c]][1]);
    }
  }
  for (i = 0; i < (E[center].size()); i++)
    if (vis[E[center][i].first] == 0) split(E[center][i].first, cand[i]);
}
void solve() {
  int i, j, k, l, r, x, y;
  string s;
  cin >> N;
  for (i = 0; i < (N); i++) cin >> OE[i];
  for (i = 0; i < (N - 1); i++) {
    cin >> X[i] >> Y[i] >> OO[i] >> EE[i];
    X[i]--;
    Y[i]--;
    E2[X[i] * 2].push_back({Y[i] * 2, OO[i]});
    E2[Y[i] * 2].push_back({X[i] * 2, OO[i]});
    E2[X[i] * 2 + 1].push_back({Y[i] * 2 + 1, EE[i]});
    E2[Y[i] * 2 + 1].push_back({X[i] * 2 + 1, EE[i]});
  }
  for (i = 0; i < (N); i++) {
    E[N].push_back({i, OE[i]});
    D[i] = 1LL << 60;
  }
  for (i = 0; i < (N - 1); i++) {
    E[X[i]].push_back({Y[i], OO[i] + EE[i]});
    E[Y[i]].push_back({X[i], OO[i] + EE[i]});
  }
  priority_queue<pair<signed long long, int>> PQ;
  PQ.push({0, N});
  while (PQ.size()) {
    signed long long co = -PQ.top().first;
    int cur = PQ.top().second;
    PQ.pop();
    if (D[cur] != co) continue;
    for (auto& e : E[cur])
      if (D[e.first] > co + e.second) {
        D[e.first] = co + e.second;
        PQ.push({-D[e.first], e.first});
      }
  }
  for (i = 0; i < (N); i++) {
    OE[i] = min(OE[i], D[i]);
    E2[i * 2].push_back({i * 2 + 1, OE[i]});
    E2[i * 2 + 1].push_back({i * 2, OE[i]});
  }
  cin >> Q;
  vector<int> cand;
  for (i = 0; i < (Q); i++) {
    cin >> U[i] >> V[i];
    U[i]--, V[i]--;
    cand.push_back(i);
  }
  split(0, cand);
  for (i = 0; i < (Q); i++) cout << ret[i] << endl;
}
int main(int argc, char** argv) {
  string s;
  int i;
  if (argc == 1) ios::sync_with_stdio(false), cin.tie(0);
  for (i = 0; i < (argc - 1); i++) s += argv[i + 1], s += '\n';
  for (i = 0; i < (s.size()); i++) ungetc(s[s.size() - 1 - i], stdin);
  cout.tie(0);
  solve();
  return 0;
}