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 maxn = 3e5 + 10, mod = 1e9 + 7;
const long long inf = 1e18;
long long W[maxn];
pair<pair<long long, long long>, pair<long long, long long> > val[4 * maxn],
    vv[maxn];
vector<pair<int, pair<long long, long long> > > v[maxn];
int h[maxn], tp[maxn], sth_really_strange[maxn], SZ[maxn], who[maxn], C;
bool mark[maxn];
int prep(int u, int par = 0) {
  SZ[u] = 1;
  for (auto p : v[u]) {
    if (p.first != par) SZ[u] += prep(p.first, u);
  }
  return SZ[u];
}
void dfs(int u, int par = 0, bool is = 1, long long W1 = 0, long long W2 = 0) {
  vv[u].first.first = min(W1, W[par] + W[u] + W2);
  vv[u].second.second = min(W2, W[par] + W[u] + W1);
  vv[u].first.second = min(W1 + W[par], W[u] + W2);
  vv[u].second.first = min(W2 + W[par], W[u] + W1);
  sth_really_strange[u] = ++C;
  who[C] = u;
  h[u] = h[par] + 1;
  if (is)
    tp[u] = u;
  else
    tp[u] = tp[par];
  sort(v[u].begin(), v[u].end(),
       [](pair<int, pair<long long, long long> > a,
          pair<int, pair<long long, long long> > b) {
         return SZ[a.first] < SZ[b.first];
       });
  if (par == 0) v[u].push_back({0, {-1, -1}});
  if (int((v[u]).size()) > 1)
    dfs(v[u][int((v[u]).size()) - 2].first, u, 0,
        v[u][int((v[u]).size()) - 2].second.first,
        v[u][int((v[u]).size()) - 2].second.second);
  for (int i = 0; i < int((v[u]).size()) - 2; i++)
    dfs(v[u][i].first, u, 1, v[u][i].second.first, v[u][i].second.second);
}
pair<pair<long long, long long>, pair<long long, long long> > operator+(
    pair<pair<long long, long long>, pair<long long, long long> > a,
    pair<pair<long long, long long>, pair<long long, long long> > b) {
  pair<pair<long long, long long>, pair<long long, long long> > c;
  c.first.first =
      min(a.first.first + b.first.first, a.first.second + b.second.first);
  c.first.second =
      min(a.first.second + b.second.second, a.first.first + b.first.second);
  c.second.first =
      min(a.second.first + b.first.first, a.second.second + b.second.first);
  c.second.second =
      min(a.second.second + b.second.second, a.second.first + b.first.second);
  return c;
}
void build(int l = 0, int r = C, int id = 1) {
  if (r - l == 1) {
    val[id] = vv[who[r]];
    return;
  }
  int mid = (l + r) >> 1;
  build(l, mid, 2 * id);
  build(mid, r, 2 * id + 1);
  val[id] = val[2 * id + 1] + val[2 * id];
}
pair<pair<long long, long long>, pair<long long, long long> > Ask(int f, int s,
                                                                  int l = 0,
                                                                  int r = C,
                                                                  int id = 1) {
  if (f >= s || l >= r || s <= l || r <= f) return {{0, inf}, {inf, 0}};
  if (f <= l && r <= s) return val[id];
  int mid = (l + r) >> 1;
  return Ask(f, s, mid, r, 2 * id + 1) + Ask(f, s, l, mid, 2 * id);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> W[i];
  }
  for (int i = 1; i <= n - 1; i++) {
    int a, b;
    cin >> a >> b;
    long long A, B;
    cin >> A >> B;
    v[a].push_back({b, {A, B}});
    v[b].push_back({a, {A, B}});
  }
  priority_queue<pair<long long, long long>,
                 vector<pair<long long, long long> >,
                 greater<pair<long long, long long> > >
      pq;
  for (int i = 1; i <= n; i++) {
    pq.push({W[i], i});
  }
  while (int((pq).size())) {
    int u = pq.top().second;
    pq.pop();
    if (mark[u]) continue;
    mark[u] = 1;
    for (pair<int, pair<long long, long long> > p : v[u]) {
      if (W[p.first] > W[u] + p.second.first + p.second.second)
        W[p.first] = W[u] + p.second.first + p.second.second,
        pq.push({W[p.first], p.first});
    }
  }
  prep(1);
  dfs(1);
  build();
  int q;
  cin >> q;
  while (q--) {
    int A, B;
    cin >> A >> B;
    bool a = 1 - (A & 1), b = 1 - (B & 1);
    A = (A + 1) >> 1, B = (B + 1) >> 1;
    pair<pair<long long, long long>, pair<long long, long long> >
        wa = {{0, W[A]}, {W[A], 0}},
        wb = {{0, W[B]}, {W[B], 0}};
    while (tp[A] != tp[B]) {
      if (h[tp[A]] < h[tp[B]]) swap(A, B), swap(wa, wb), swap(a, b);
      wa = wa + Ask(sth_really_strange[tp[A]] - 1, sth_really_strange[A]);
      A = v[tp[A]].back().first;
    }
    if (h[A] < h[B]) swap(A, B), swap(wa, wb), swap(a, b);
    wa = wa + Ask(sth_really_strange[B], sth_really_strange[A]);
    swap(wb.first.second, wb.second.first);
    wa = wa + wb;
    long long ans = inf;
    if (a == 0 && b == 0) ans = wa.first.first;
    if (a == 0 && b == 1) ans = wa.first.second;
    if (a == 1 && b == 0) ans = wa.second.first;
    if (a == 1 && b == 1) ans = wa.second.second;
    cout << ans << "\n";
  }
}