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 N = 300005;
int n;
long long w[N];
vector<pair<int, pair<long long, long long>>> g[N];
void dijk() {
  vector<int> used(N);
  priority_queue<pair<long long, int>> q;
  for (int i = 1; i <= n; i++) q.push(make_pair(-w[i], i));
  while (!q.empty()) {
    int v = -1;
    do {
      v = q.top().second;
      q.pop();
    } while (used[v] && !q.empty());
    if (used[v]) break;
    used[v] = 1;
    for (int i = 0; i < g[v].size(); i++) {
      int to = g[v][i].first;
      long long d = g[v][i].second.first + g[v][i].second.second;
      if (w[v] + d < w[to]) {
        w[to] = w[v] + d;
        q.push(make_pair(-w[to], to));
      }
    }
  }
}
int k, up[N][25], timer, tin[N], tout[N];
long long dp[N][25][2][2], W[N][2];
void dfs(int v, int p) {
  up[v][0] = p;
  for (int a = 0; a <= 1; a++)
    for (int b = 0; b <= 1; b++) {
      if (a == b)
        dp[v][0][a][b] = min(W[v][a], W[v][b] + w[v] + w[p]);
      else
        dp[v][0][a][b] = min(W[v][a] + w[p], W[v][b] + w[v]);
    }
  for (int i = 1; i <= k; i++) {
    up[v][i] = up[up[v][i - 1]][i - 1];
    int p = up[v][i - 1];
    for (int a = 0; a <= 1; a++)
      for (int b = 0; b <= 1; b++) {
        dp[v][i][a][b] = 1000000007ll * 1000000007ll;
        for (int c = 0; c <= 1; c++)
          dp[v][i][a][b] =
              min(dp[v][i][a][b], dp[v][i - 1][a][c] + dp[p][i - 1][c][b]);
      }
  }
  tin[v] = ++timer;
  for (int i = 0; i < g[v].size(); i++) {
    int to = g[v][i].first;
    if (to == p) continue;
    W[to][0] = g[v][i].second.first;
    W[to][1] = g[v][i].second.second;
    dfs(to, v);
  }
  tout[v] = ++timer;
}
bool upper(int a, int b) { return (tin[a] <= tin[b] && tout[a] >= tout[b]); }
int lca(int a, int b) {
  if (upper(a, b)) return a;
  if (upper(b, a)) return b;
  for (int i = k; i >= 0; i--)
    if (!upper(up[a][i], b)) a = up[a][i];
  return up[a][0];
}
long long get(int a, int b, int A, int B) {
  if (a == b) return (A != B) * (w[a]);
  vector<long long> now(2, 0);
  now[A] = 0;
  now[!A] = w[a];
  for (int i = k; i >= 0; i--) {
    if (!upper(up[a][i], b)) {
      vector<long long> nxt(2, 0);
      for (int x = 0; x <= 1; x++)
        nxt[x] = min(now[x] + dp[a][i][x][x], now[!x] + dp[a][i][!x][x]);
      a = up[a][i];
      now = nxt;
    }
  }
  vector<long long> nxt(2, 0);
  for (int x = 0; x <= 1; x++)
    nxt[x] = min(now[x] + dp[a][0][x][x], now[!x] + dp[a][0][!x][x]);
  now = nxt;
  return now[B];
}
long long answer(int a, int b) {
  int A = a % 2, B = b % 2;
  a = (a + 1) / 2;
  b = (b + 1) / 2;
  int g = lca(a, b);
  return min(
      min(get(a, g, A, 0) + get(b, g, B, 0), get(a, g, A, 1) + get(b, g, B, 1)),
      w[g] + min(get(a, g, A, 1) + get(b, g, B, 0),
                 get(a, g, A, 0) + get(b, g, B, 1)));
}
int main() {
  cin >> n;
  while ((1 << k) <= n) k++;
  for (int i = 1; i <= n; i++) scanf("%lld", w + i);
  for (int i = 1; i <= n - 1; i++) {
    int a, b;
    long long d1, d2;
    scanf("%d%d%lld%lld", &a, &b, &d2, &d1);
    g[a].push_back(make_pair(b, make_pair(d1, d2)));
    g[b].push_back(make_pair(a, make_pair(d1, d2)));
  }
  dijk();
  dfs(1, 1);
  int q;
  cin >> q;
  while (q--) {
    int a, b;
    scanf("%d%d", &a, &b);
    printf("%lld\n", answer(a, b));
  }
  return 0;
}