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>
#pragma GCC optimize "-O3"
#pragma GCC target("avx,avx2,fma")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
using namespace std;
int n;
vector<int> v;
vector<tuple<int, int, int> > g[300002];
vector<pair<int, long long int> > vv[300002];
vector<pair<long long int, long long int> > V[300002];
long long int dist[300002];
priority_queue<pair<long long int, int>, vector<pair<long long int, int> >,
               greater<pair<long long int, int> > >
    q;
struct st {
  long long int dp[2][2];
  int l;
  int r;
  st() {
    dp[0][0] = dp[0][1] = dp[1][0] = dp[1][1] = LLONG_MAX;
    l = -1;
    r = -1;
  }
  void set_node(int x) {
    dp[0][0] = 0;
    dp[1][1] = 0;
    dp[0][1] = dist[x];
    dp[1][0] = dist[x];
    l = r = x;
  }
  st flip() {
    swap(l, r);
    swap(dp[0][1], dp[1][0]);
    return (*this);
  }
};
map<pair<int, int>, long long int> mp;
pair<long long int, long long int> look[300002];
int dep[300002];
int lcc[19][300002];
st pat[19][300002];
inline long long int ds(int t1, int node1, int t2, int node2) {
  if (lcc[0][node1] != node2) swap(node1, node2);
  if (t1 == 0) {
    return look[node1].first;
  } else {
    return look[node1].second;
  }
}
inline st merge(st a, st b) {
  if (a.l == -1) {
    return b;
  }
  if (b.l == -1) {
    return a;
  }
  st r;
  r.l = a.l;
  r.r = b.r;
  long long int w[] = {ds(0, a.r, 0, b.l), ds(1, a.r, 1, b.l)};
  for (int i = 0; i < 2; i++) {
    for (int j = 0; j < 2; j++) {
      for (int k = 0; k < 2; k++) {
        long long int cs = a.dp[i][j] + b.dp[j][k];
        cs += w[j];
        r.dp[i][k] = min(r.dp[i][k], cs);
      }
    }
  }
  return r;
}
inline void dfs(int a, int d = 0, int p = -1,
                pair<long long int, long long int> c = make_pair(-1, -1)) {
  lcc[0][a] = p;
  dep[a] = d;
  look[a] = c;
  int idx = 0;
  for (auto go : vv[a]) {
    if (go.first == p) {
      idx++;
      continue;
    }
    dfs(go.first, d + 1, a, V[a][idx]);
    idx++;
  }
}
int lca(int a, int b) {
  if (dep[a] < dep[b]) swap(a, b);
  for (int i = 0; i < 19; i++) {
    if (((dep[a] - dep[b]) >> i) & 1) {
      a = lcc[i][a];
    }
  }
  if (a == b) return a;
  for (int i = 19 - 1; i >= 0; i--) {
    if (lcc[i][a] != lcc[i][b]) {
      a = lcc[i][a];
      b = lcc[i][b];
    }
  }
  return lcc[0][a];
}
inline st go(int a, int f) {
  st r;
  if (f == 0) {
    return r;
  }
  for (int i = 0; i < 19; i++) {
    if ((f >> i) & 1) {
      r = merge(r, pat[i][a]);
      a = lcc[i][a];
    }
  }
  return r;
}
int qq;
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    long long int w;
    scanf("%lld", &w);
    v.push_back(w);
    vv[n].push_back(make_pair(i, w));
  }
  for (int i = 1; i < n; i++) {
    long long int a, b, c, d;
    scanf("%lld%lld%lld%lld", &a, &b, &c, &d);
    a--;
    b--;
    g[a].push_back(make_tuple(b, c, d));
    g[b].push_back(make_tuple(a, c, d));
    vv[a].push_back(make_pair(b, c + d));
    vv[b].push_back(make_pair(a, c + d));
    V[a].push_back(make_pair(c, d));
    V[b].push_back(make_pair(c, d));
  }
  memset(dist, -1, sizeof(dist));
  dist[n] = 0;
  q.push(make_pair(0, n));
  while (!q.empty()) {
    int b = q.top().second;
    long long int cc = q.top().first;
    q.pop();
    if (dist[b] != cc) continue;
    for (auto go : vv[b]) {
      if (dist[go.first] == -1 || dist[go.first] > dist[b] + go.second) {
        dist[go.first] = dist[b] + go.second;
        q.push(make_pair(dist[go.first], go.first));
      }
    }
  }
  dfs(0);
  for (int j = 0; j < n; j++) {
    pat[0][j].set_node(j);
  }
  for (int i = 0; i + 1 < 19; i++) {
    for (int j = 0; j < n; j++) {
      if (lcc[i][j] != -1) {
        lcc[i + 1][j] = lcc[i][lcc[i][j]];
        pat[i + 1][j] = merge(pat[i][j], pat[i][lcc[i][j]]);
      } else {
        lcc[i + 1][j] = -1;
      }
    }
  }
  cin >> qq;
  while (qq--) {
    int l, r;
    scanf("%d%d", &l, &r);
    l--;
    r--;
    l = (l / 2) + (l % 2) * n;
    r = (r / 2) + (r % 2) * n;
    int L = l;
    int R = r;
    if (L >= n) L -= n;
    if (R >= n) R -= n;
    swap(l, L);
    swap(r, R);
    int lc = lca(l, r);
    st ret = merge(go(l, dep[l] - dep[lc] + 1), go(r, dep[r] - dep[lc]).flip());
    printf("%lld\n", ret.dp[L >= n][R >= n]);
  }
  return 0;
}