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;
long long read() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch <= '9' && ch >= '0') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return f * x;
}
struct edge {
  long long nxt, to, v1, v2;
} ed[605000];
struct node {
  node friend operator+(node a, node b) {
    node ans;
    ans.o[0][0] = min(a.o[0][0] + b.o[0][0], a.o[0][1] + b.o[1][0]);
    ans.o[1][1] = min(a.o[1][0] + b.o[0][1], a.o[1][1] + b.o[1][1]);
    ans.o[0][1] = min(a.o[0][0] + b.o[0][1], a.o[0][1] + b.o[1][1]);
    ans.o[1][0] = min(a.o[1][0] + b.o[0][0], a.o[1][1] + b.o[1][0]);
    return ans;
  }
  long long o[2][2];
} g[305000][20];
long long n, m, rev[305000], a, b, c, d, used[305000];
long long head[305000], cnt, _head[305000], _cnt, __head[305000], __cnt;
long long f[305000][20], dep[305000];
void add(long long a, long long b, long long c, long long d) {
  ed[++cnt].to = b;
  ed[cnt].v1 = c;
  ed[cnt].v2 = d;
  ed[cnt].nxt = head[a];
  head[a] = cnt;
}
void dfs1(int pos) {
  used[pos]++;
  for (int i = head[pos]; i; i = ed[i].nxt) {
    if (!used[ed[i].to]) {
      dfs1(ed[i].to);
      rev[pos] = min(rev[pos], rev[ed[i].to] + ed[i].v1 + ed[i].v2);
    }
  }
}
void dfs2(int pos) {
  used[pos]++;
  for (int i = head[pos]; i; i = ed[i].nxt) {
    if (!used[ed[i].to]) {
      rev[ed[i].to] = min(rev[ed[i].to], rev[pos] + ed[i].v1 + ed[i].v2);
      dfs2(ed[i].to);
    }
  }
}
void dfs3(int pos) {
  used[pos]++;
  for (int i = head[pos]; i; i = ed[i].nxt) {
    if (!used[ed[i].to]) {
      f[ed[i].to][0] = pos;
      dep[ed[i].to] = dep[pos] + 1;
      g[ed[i].to][0].o[0][0] =
          min(ed[i].v1, rev[pos] + ed[i].v2 + rev[ed[i].to]);
      g[ed[i].to][0].o[0][1] =
          min(ed[i].v1 + rev[pos], ed[i].v2 + rev[ed[i].to]);
      g[ed[i].to][0].o[1][0] =
          min(ed[i].v2 + rev[pos], ed[i].v1 + rev[ed[i].to]);
      g[ed[i].to][0].o[1][1] =
          min(ed[i].v2, rev[pos] + ed[i].v1 + rev[ed[i].to]);
      dfs3(ed[i].to);
    }
  }
}
void query(int a, int b) {
  int x = (a + 1) / 2, y = (b + 1) / 2;
  if (x == y) {
    if (a == b)
      printf("0\n");
    else
      printf("%lld\n", rev[x]);
    return;
  }
  node o1 = {0, 1000000000000000ll, 1000000000000000ll, 0},
       o2 = {0, 1000000000000000ll, 1000000000000000ll, 0};
  if (dep[x] < dep[y]) swap(a, b), swap(x, y);
  for (int i = 19; i >= 0; i--) {
    if (dep[f[x][i]] >= dep[y]) {
      o1 = o1 + g[x][i];
      x = f[x][i];
    }
  }
  if (x == y) {
    printf("%lld\n", o1.o[(a & 1) ^ 1][(b & 1) ^ 1]);
    return;
  }
  for (int i = 19; i >= 0; i--) {
    if (f[x][i] != f[y][i]) {
      o1 = o1 + g[x][i];
      o2 = o2 + g[y][i];
      x = f[x][i];
      y = f[y][i];
    }
  }
  o1 = o1 + g[x][0];
  o2 = o2 + g[y][0];
  printf("%lld\n", min(o1.o[(a & 1) ^ 1][0] + o2.o[(b & 1) ^ 1][0],
                       o1.o[(a & 1) ^ 1][1] + o2.o[(b & 1) ^ 1][1]));
}
int main() {
  n = read();
  dep[1] = 1;
  for (int i = 1; i <= n; i++) rev[i] = read();
  for (int i = 1; i < n; i++) {
    a = read();
    b = read();
    c = read();
    d = read();
    add(a, b, c, d);
    add(b, a, c, d);
  }
  dfs1(1);
  memset(used, 0, sizeof(used));
  dfs2(1);
  memset(used, 0, sizeof(used));
  dfs3(1);
  memset(used, 0, sizeof(used));
  g[1][0].o[0][1] = g[1][0].o[1][0] = rev[1];
  for (int i = 1; i <= 19; i++) {
    for (int j = 1; j <= n; j++) {
      f[j][i] = f[f[j][i - 1]][i - 1];
      g[j][i] = g[j][i - 1] + g[f[j][i - 1]][i - 1];
    }
  }
  m = read();
  for (int i = 1; i <= m; i++) {
    a = read();
    b = read();
    query(a, b);
  }
  return 0;
}