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 MOD = 1000000007;
const long long INF = 2e9;
const long long INFLL = 1e18;
const int MAX_N = 300000;
const int MAX_K = 20;
int N, Q;
long long ch[MAX_N + 1];
struct S {
  int y;
  long long d0, d1;
};
vector<S> gp[MAX_N + 1];
S p[MAX_N + 1];
int in[MAX_N + 1], out[MAX_N + 1], cnt, ind[MAX_N + 1];
long long dist[MAX_N + 1];
int lv[MAX_N + 1];
void dfs1(int x) {
  in[x] = ++cnt;
  ind[in[x]] = x;
  for (S i : gp[x]) {
    if (i.y == p[x].y) continue;
    p[i.y].y = x;
    p[i.y].d0 = i.d0;
    p[i.y].d1 = i.d1;
    dist[i.y] = dist[x] + i.d0 + i.d1;
    lv[i.y] = lv[x] + 1;
    dfs1(i.y);
  }
  out[x] = cnt;
}
struct SEG {
  struct NODE {
    int l, r;
    long long mn, lazy;
  };
  int SZ;
  vector<NODE> seg;
  void add() { seg.push_back({-1, -1, 0, 0}); }
  void calc(int idx) {
    if (seg[idx].lazy != 0 && seg[idx].l != -1) {
      seg[seg[idx].l].mn += seg[idx].lazy;
      seg[seg[idx].l].lazy += seg[idx].lazy;
      seg[seg[idx].r].mn += seg[idx].lazy;
      seg[seg[idx].r].lazy += seg[idx].lazy;
      seg[idx].lazy = 0;
    }
  }
  void Init(int x) {
    add();
    SZ = x;
    init(0, 1, SZ);
  }
  void init(int idx, int s, int e) {
    if (s == e) {
      seg[idx].mn = dist[ind[s]] + ch[ind[s]];
      return;
    }
    seg[idx].l = seg.size();
    add();
    seg[idx].r = seg.size();
    add();
    init(seg[idx].l, s, (s + e) / 2);
    init(seg[idx].r, (s + e) / 2 + 1, e);
    seg[idx].mn = min(seg[seg[idx].l].mn, seg[seg[idx].r].mn);
  }
  void Update(int x, int y, long long z) { update(0, 1, SZ, x, y, z); }
  void update(int idx, int s, int e, int x, int y, long long z) {
    calc(idx);
    if (x <= s && e <= y) {
      seg[idx].lazy += z;
      seg[idx].mn += z;
      return;
    }
    if (x > e || y < s) return;
    update(seg[idx].l, s, (s + e) / 2, x, y, z);
    update(seg[idx].r, (s + e) / 2 + 1, e, x, y, z);
    seg[idx].mn = min(seg[seg[idx].l].mn, seg[seg[idx].r].mn);
  }
  long long Mn(int x, int y) { return mn(0, 1, SZ, x, y); }
  long long mn(int idx, int s, int e, int x, int y) {
    calc(idx);
    if (x <= s && e <= y) {
      return seg[idx].mn;
    }
    if (x > e || y < s) return INFLL;
    return min(mn(seg[idx].l, s, (s + e) / 2, x, y),
               mn(seg[idx].r, (s + e) / 2 + 1, e, x, y));
  }
} Seg;
void dfs2(int x) {
  ch[x] = min(ch[x], Seg.Mn(1, N));
  for (S i : gp[x]) {
    if (i.y == p[x].y) continue;
    int nxt = i.y;
    Seg.Update(1, in[nxt] - 1, p[nxt].d0 + p[nxt].d1);
    Seg.Update(in[nxt], out[nxt], -p[nxt].d0 - p[nxt].d1);
    Seg.Update(out[nxt] + 1, N, p[nxt].d0 + p[nxt].d1);
    dfs2(nxt);
    Seg.Update(1, in[nxt] - 1, -p[nxt].d0 - p[nxt].d1);
    Seg.Update(in[nxt], out[nxt], p[nxt].d0 + p[nxt].d1);
    Seg.Update(out[nxt] + 1, N, -p[nxt].d0 - p[nxt].d1);
  }
}
int up[MAX_N + 1][MAX_K + 1];
long long d[2][2][MAX_N + 1][MAX_K + 1];
void dfs3(int x) {
  up[x][0] = p[x].y;
  d[0][0][x][0] = min(p[x].d0, ch[x] + p[x].d1 + ch[p[x].y]);
  d[0][1][x][0] = min(ch[x] + p[x].d1, p[x].d0 + ch[p[x].y]);
  d[1][0][x][0] = min(ch[x] + p[x].d0, p[x].d1 + ch[p[x].y]);
  d[1][1][x][0] = min(p[x].d1, ch[x] + p[x].d0 + ch[p[x].y]);
  for (int i = 1; i < MAX_K; i++) {
    up[x][i] = up[up[x][i - 1]][i - 1];
    for (int j = 0; j < 2; j++) {
      for (int k = 0; k < 2; k++) {
        d[j][k][x][i] = min(d[j][0][x][i - 1] + d[0][k][up[x][i - 1]][i - 1],
                            d[j][1][x][i - 1] + d[1][k][up[x][i - 1]][i - 1]);
      }
    }
  }
  for (S i : gp[x]) {
    if (i.y == p[x].y) continue;
    dfs3(i.y);
  }
}
int lca(int x, int y) {
  for (int i = MAX_K - 1; i >= 0; i--) {
    if (lv[up[x][i]] >= lv[y]) x = up[x][i];
    if (lv[up[y][i]] >= lv[x]) y = up[y][i];
  }
  if (x == y) return x;
  for (int i = MAX_K - 1; i >= 0; i--) {
    if (up[x][i] != up[y][i]) {
      x = up[x][i];
      y = up[y][i];
    }
  }
  return up[x][0];
}
long long di[2][2];
long long cd(int x, int tx, int y, int ty) {
  di[0][0] = di[0][1] = di[1][1] = di[1][0] = 0LL;
  di[0][1 - tx] = ch[x];
  for (int i = MAX_K - 1; i >= 0; i--) {
    if (lv[up[x][i]] >= lv[y]) {
      di[1][0] = min(di[0][0] + d[0][0][x][i], di[0][1] + d[1][0][x][i]);
      di[1][1] = min(di[0][0] + d[0][1][x][i], di[0][1] + d[1][1][x][i]);
      di[0][0] = di[1][0];
      di[0][1] = di[1][1];
      x = up[x][i];
    }
  }
  return di[0][ty];
}
int main() {
  scanf("%d", &N);
  for (int i = 1; i <= N; i++) {
    scanf("%lld", &ch[i]);
  }
  for (int i = 1; i < N; i++) {
    int a, b;
    long long c1, c2;
    scanf("%d%d%lld%lld", &a, &b, &c1, &c2);
    gp[a].push_back({b, c1, c2});
    gp[b].push_back({a, c1, c2});
  }
  lv[1] = 1;
  dfs1(1);
  Seg.Init(N);
  dfs2(1);
  dfs3(1);
  scanf("%d", &Q);
  while (Q--) {
    int a, b;
    scanf("%d%d", &a, &b);
    a++;
    b++;
    int l = lca(a / 2, b / 2);
    printf("%lld\n", min(cd(a / 2, a % 2, l, 0) + cd(b / 2, b % 2, l, 0),
                         cd(a / 2, a % 2, l, 1) + cd(b / 2, b % 2, l, 1)));
  }
  return 0;
}