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 inf = 2 * (1e9) + 10;
const long long infl = 2 * (1e18) + 10;
const long long MOD = 998244353;
const long NMAX = 400005;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
struct segment {
  long long states[2][2];
  segment(int l = 0, int r = 0) {
    this->l = l;
    this->r = r;
    memset(states, 0, sizeof(states));
    states[0][1] = infl;
    states[1][0] = infl;
  }
  int l, r;
};
struct edge {
  int to;
  long long w1;
  long long w2;
  edge(long long to = 0, long long w1 = 0, long long w2 = 0) {
    this->to = to;
    this->w1 = w1;
    this->w2 = w2;
  }
};
long long w1[NMAX], w2[NMAX], c[NMAX];
int pa[NMAX];
vector<edge> E[NMAX];
int n, m;
int cnt[NMAX], l[NMAX];
int nod[NMAX];
int num[NMAX];
int dp[25][NMAX];
vector<int> lst[NMAX];
segment combine(segment a, segment b) {
  segment ab;
  for (int i = 0; i <= 1; ++i) {
    for (int j = 0; j <= 1; ++j) {
      ab.states[i][j] = infl;
      for (int n = 0; n <= 1; ++n) {
        for (int m = 0; m <= 1; ++m) {
          long long comm = infl;
          if (n == 0 && m == 0)
            comm = min(w1[nod[b.l]], w2[nod[b.l]] + c[nod[a.r]] + c[nod[b.l]]);
          if (n == 0 && m == 1)
            comm = min(w1[nod[b.l]] + c[nod[b.l]], w2[nod[b.l]] + c[nod[a.r]]);
          if (n == 1 && m == 0)
            comm = min(w1[nod[b.l]] + c[nod[a.r]], w2[nod[b.l]] + c[nod[b.l]]);
          if (n == 1 && m == 1)
            comm = min(w1[nod[b.l]] + c[nod[a.r]] + c[nod[b.l]], w2[nod[b.l]]);
          ab.states[i][j] =
              min(ab.states[i][j], a.states[i][n] + b.states[m][j] + comm);
        }
      }
    }
  }
  ab.l = a.l;
  ab.r = b.r;
  return ab;
}
segment combine2(segment a, segment b) {
  segment ab;
  for (int i = 0; i <= 1; ++i) {
    for (int j = 0; j <= 1; ++j) {
      ab.states[i][j] = infl;
      ab.states[i][j] = min(
          min(a.states[0][i] + b.states[0][j], a.states[1][i] + b.states[1][j]),
          min(a.states[0][i] + c[nod[a.l]] + b.states[1][j],
              a.states[1][i] + c[nod[a.l]] + b.states[0][j]));
    }
  }
  return ab;
}
segment t[4 * NMAX];
segment query(int n, int l, int r, int ql, int qr) {
  if (ql <= l && r <= qr) return t[n];
  int pivot = (l + r) / 2;
  segment rs;
  if (ql <= pivot) rs = query(2 * n, l, pivot, ql, qr);
  if (qr > pivot) {
    segment rsr = query(2 * n + 1, pivot + 1, r, ql, qr);
    if (rs.l)
      rs = combine(rs, rsr);
    else
      rs = rsr;
  }
  return rs;
}
void build(int n, int l, int r) {
  if (l == r) {
    t[n].states[0][1] = c[nod[l]];
    t[n].states[1][0] = c[nod[l]];
    t[n].l = l;
    t[n].r = r;
    return;
  }
  int pivot = (l + r) / 2;
  build(2 * n, l, pivot);
  build(2 * n + 1, pivot + 1, r);
  t[n] = combine(t[2 * n], t[2 * n + 1]);
}
void make_HLD(int x, int p, int d) {
  cnt[x] = 1;
  l[x] = d;
  if (x != 1 && E[x].size() == 1) {
    lst[m].push_back(x);
    num[x] = m++;
    return;
  }
  int mi = 0;
  for (edge y : E[x]) {
    if (y.to == p) continue;
    make_HLD(y.to, x, d + 1);
    pa[y.to] = x;
    w1[y.to] = y.w1;
    w2[y.to] = y.w2;
    cnt[x] += cnt[y.to];
    if (cnt[y.to] > cnt[mi]) mi = y.to;
  }
  num[x] = num[mi];
  lst[num[x]].push_back(x);
}
int lca(int v, int w) {
  if (l[v] < l[w]) swap(v, w);
  for (int step = log2(l[v]) + 1; step >= 0; --step)
    if (l[v] - (1 << step) >= l[w]) v = dp[step][v];
  if (v == w) return v;
  for (int step = log2(l[w]) + 1; step >= 0; --step)
    if (dp[step][v] && dp[step][v] != dp[step][w])
      v = dp[step][v], w = dp[step][w];
  return dp[0][v];
}
segment subpath(int v, int u) {
  segment rs;
  while (num[v] != num[u]) {
    segment prs = query(1, 1, n, cnt[lst[num[v]].back()], cnt[v]);
    if (!rs.l) {
      rs = prs;
    } else {
      rs = combine(prs, rs);
    }
    v = pa[lst[num[v]].back()];
    if (v < 1) break;
  }
  if (v >= 1) {
    segment prs;
    prs = query(1, 1, n, cnt[u], cnt[v]);
    if (!rs.l) {
      rs = prs;
    } else {
      rs = combine(prs, rs);
    }
  }
  return rs;
}
int main() {
  cin.sync_with_stdio(0);
  cin >> n;
  long long a, b;
  for (int i = 1; i <= n; ++i) {
    cin >> a;
    c[i] = a;
  }
  cnt[0] = -1;
  for (int i = 1; i < n; ++i) {
    long long ww1, ww2;
    cin >> a >> b >> ww1 >> ww2;
    E[a].push_back(edge(b, ww1, ww2));
    E[b].push_back(edge(a, ww1, ww2));
  }
  set<pair<long long, int>> T;
  for (int i = 1; i <= n; ++i) {
    T.insert(make_pair(c[i], i));
  }
  while (!T.empty()) {
    int v = (*(T.begin())).second;
    T.erase(T.begin());
    for (auto el : E[v]) {
      if (c[v] + el.w1 + el.w2 < c[el.to]) {
        c[el.to] = c[v] + el.w1 + el.w2;
        T.insert(make_pair(c[el.to], el.to));
      }
    }
  }
  make_HLD(1, 0, 0);
  for (int i = 1; i <= n; ++i) {
    dp[0][i] = pa[i];
  }
  for (int step = 1; (1 << step) <= n; ++step)
    for (int i = 1; i <= n; ++i) dp[step][i] = dp[step - 1][dp[step - 1][i]];
  int x = n;
  for (int i = 0; i < m; i++) {
    for (int j : lst[i]) {
      nod[x] = j;
      cnt[j] = x--;
    }
  }
  build(1, 1, n);
  int q;
  cin >> q;
  for (int i = 1; i <= q; ++i) {
    int u, v;
    cin >> u >> v;
    int u1 = (u - 1) / 2 + 1;
    int v1 = (v - 1) / 2 + 1;
    int lc = lca(u1, v1);
    segment rs;
    if (lc == u1 || lc == v1) {
      if (l[u1] < l[v1]) {
        rs = subpath(v1, u1);
        cout << rs.states[1 - u % 2][1 - v % 2] << "\n";
      } else {
        rs = subpath(u1, v1);
        cout << rs.states[1 - v % 2][1 - u % 2] << "\n";
      }
    } else {
      segment rs1 = subpath(u1, lc);
      segment rs2 = subpath(v1, lc);
      rs = combine2(rs1, rs2);
      cout << rs.states[1 - u % 2][1 - v % 2] << "\n";
    }
  }
  return 0;
}