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;
template <class T>
void _R(T &x) {
  cin >> x;
}
void _R(int &x) { scanf("%d", &x); }
void _R(int64_t &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template <class T, class... U>
void R(T &head, U &...tail) {
  _R(head);
  R(tail...);
}
template <class T>
void _W(const T &x) {
  cout << x;
}
void _W(const int &x) { printf("%d", x); }
void _W(const int64_t &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template <class T, class U>
void _W(const pair<T, U> &x) {
  _W(x.first);
  putchar(' ');
  _W(x.second);
}
template <class T>
void _W(const vector<T> &x) {
  for (auto i = x.begin(); i != x.end(); _W(*i++))
    if (i != x.cbegin()) putchar(' ');
}
void W() {}
template <class T, class... U>
void W(const T &head, const U &...tail) {
  _W(head);
  putchar(sizeof...(tail) ? ' ' : '\n');
  W(tail...);
}
int MOD = 1e9 + 7;
void ADD(int64_t &x, int64_t v) {
  x = (x + v) % MOD;
  if (x < 0) x += MOD;
}
const int SIZE = 610000;
int64_t an[SIZE];
pair<int, int> qe[SIZE];
vector<int> qx[SIZE];
int Q;
int64_t wv[SIZE];
vector<int> e[SIZE];
vector<pair<int64_t, int64_t> > ew[SIZE];
int N;
int bfs[SIZE], sons[SIZE];
int used[SIZE], tt, tt2, father[SIZE];
vector<int> qq;
void read_query() {
  R(Q);
  for (int i = 0; i < (Q); ++i) {
    R(qe[i].first, qe[i].second);
    qe[i].first--;
    qe[i].second--;
    qx[qe[i].first / 2].push_back(i);
    qx[qe[i].second / 2].push_back(i);
    an[i] = 1e18;
  }
}
void build(int st) {
  bfs[0] = st;
  tt2--;
  used[st] = tt2;
  int i = 0, j = 1;
  for (; i < j; i++) {
    int x = bfs[i];
    sons[x] = 1;
    for (int k = 0; k < (((int)(e[x]).size())); ++k) {
      int y = e[x][k];
      if (used[y] == tt || used[y] == tt2) continue;
      father[y] = x;
      used[y] = tt2;
      bfs[j++] = y;
    }
  }
  int num = j;
  for (i = j - 1; i >= 0; i--) {
    int x = bfs[i];
    if (sons[x] * 2 >= num) {
      qq.push_back(x);
      used[x] = tt;
      for (int k = 0; k < (((int)(e[x]).size())); ++k) {
        int y = e[x][k];
        if (used[y] != tt) build(y);
      }
      return;
    }
    sons[father[x]] += sons[x];
  }
}
void init() {
  tt++;
  qq.clear();
  build(0);
}
int64_t dp[SIZE][2][2];
template <class T>
void mii(T &x, T y) {
  if (x > y) x = y;
}
int from[SIZE], from_eid[SIZE];
int now_use[SIZE];
void add(int center) {
  bfs[0] = center;
  tt2--;
  int rr = 1;
  for (int i = 0; i < (2); ++i)
    for (int j = 0; j < (2); ++j) dp[center][i][j] = (i == j) ? 0 : wv[center];
  for (int i = 0; i < (rr); ++i) {
    int x = bfs[i];
    now_use[x] = tt2;
    for (int j = 0; j < (((int)(e[x]).size())); ++j) {
      int y = e[x][j];
      if (used[y] == tt || used[y] == tt2) continue;
      for (int k1 = 0; k1 < (2); ++k1)
        for (int k2 = 0; k2 < (2); ++k2)
          dp[y][k1][k2] =
              dp[x][k1][k2] + ((k2) ? (ew[x][j].second) : (ew[x][j].first));
      for (int k1 = 0; k1 < (2); ++k1)
        for (int k2 = 0; k2 < (2); ++k2)
          mii(dp[y][k1][k2], dp[y][k1][k2 ^ 1] + wv[y]);
      from[y] = x;
      from_eid[y] = j;
      used[y] = tt2;
      bfs[rr++] = y;
    }
  }
  for (int i = rr - 1; i > 0; i--) {
    int y = bfs[i];
    int x = from[y];
    mii(wv[x],
        wv[y] +
            ((0) ? (ew[x][from_eid[y]].second) : (ew[x][from_eid[y]].first)) +
            ((1) ? (ew[x][from_eid[y]].second) : (ew[x][from_eid[y]].first)));
    for (int k1 = 0; k1 < (2); ++k1)
      for (int k2 = 0; k2 < (2); ++k2)
        mii(dp[x][k1][k2], dp[y][k1][k2] + ((k2) ? (ew[x][from_eid[y]].second)
                                                 : (ew[x][from_eid[y]].first)));
  }
  tt2--;
  rr = 1;
  mii(wv[center], dp[center][0][1]);
  for (int i = 0; i < (rr); ++i) {
    int x = bfs[i];
    now_use[x] = tt2;
    for (int j = 0; j < (((int)(e[x]).size())); ++j) {
      int y = e[x][j];
      if (used[y] == tt || used[y] == tt2) continue;
      for (int k1 = 0; k1 < (2); ++k1)
        for (int k2 = 0; k2 < (2); ++k2)
          mii(dp[y][k1][k2],
              dp[x][k1][k2] + ((k2) ? (ew[x][j].second) : (ew[x][j].first)));
      for (int k1 = 0; k1 < (2); ++k1)
        for (int k2 = 0; k2 < (2); ++k2)
          mii(dp[y][k1][k2], dp[y][k1][k2 ^ 1] + wv[y]);
      from[y] = x;
      from_eid[y] = j;
      used[y] = tt2;
      bfs[rr++] = y;
    }
  }
  for (int i = rr - 1; i > 0; i--) {
    int y = bfs[i];
    int x = from[y];
    for (int k1 = 0; k1 < (2); ++k1)
      for (int k2 = 0; k2 < (2); ++k2)
        mii(dp[x][k1][k2], dp[y][k1][k2] + ((k2) ? (ew[x][from_eid[y]].second)
                                                 : (ew[x][from_eid[y]].first)));
  }
  for (int i = 0; i < (rr); ++i) {
    for (int qid : qx[bfs[i]]) {
      int x = qe[qid].first;
      int y = qe[qid].second;
      if (now_use[x / 2] != tt2 || now_use[y / 2] != tt2) continue;
      for (int k = 0; k < (2); ++k) {
        mii(an[qid], dp[x >> 1][k][x & 1] + dp[y >> 1][k][y & 1]);
        mii(an[qid],
            dp[x >> 1][k][x & 1] + dp[y >> 1][k ^ 1][y & 1] + wv[center]);
      }
    }
  }
}
void solve() {
  tt++;
  for (int i = 0; i < (((int)(qq).size())); ++i) {
    int me = qq[i];
    used[me] = tt;
    add(me);
  }
}
int main() {
  tt++;
  R(N);
  for (int i = 0; i < (N); ++i) R(wv[i]);
  for (int i = (1); i < (N); ++i) {
    int x, y;
    R(x, y);
    int64_t v1, v2;
    R(v1, v2);
    x--;
    y--;
    e[x].push_back(y);
    ew[x].push_back({v1, v2});
    e[y].push_back(x);
    ew[y].push_back({v1, v2});
  }
  read_query();
  init();
  solve();
  W(vector<int64_t>(an, an + Q));
  return 0;
}