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 MAXN = 300005, MAXK = 19;
const long long INF = 0x3f3f3f3f3f3f3f3fll;
int n;
long long a[MAXN], cro[MAXN];
struct Edge {
  int v;
  long long c[2];
  Edge *next;
} pool[MAXN << 1 | 1], *h[MAXN];
int etot = 0;
void addEdge(Edge *h[], int u, int v, long long x, long long y) {
  Edge *p = &pool[++etot];
  p->v = v;
  p->c[0] = x;
  p->c[1] = y;
  p->next = h[u];
  h[u] = p;
}
bool vis[MAXN];
int frot[MAXN], size[MAXN];
void getroot(int u, int pa, int full, int &root) {
  size[u] = 1;
  frot[u] = 0;
  for (Edge *p = h[u]; p; p = p->next) {
    if (p->v == pa || vis[p->v]) continue;
    getroot(p->v, u, full, root);
    size[u] += size[p->v];
    frot[u] = max(frot[u], size[p->v]);
  }
  frot[u] = max(frot[u], full - size[u]);
  if (!root || frot[u] < frot[root]) root = u;
}
long long dis[MAXN][2];
void dfs1(int u, int pa, int &mini) {
  if (dis[u][0] + dis[u][1] + a[u] <= dis[mini][0] + dis[mini][1] + a[mini])
    mini = u;
  for (Edge *p = h[u]; p; p = p->next) {
    if (p->v == pa || vis[p->v]) continue;
    for (register int t = 0; t <= 1; ++t) dis[p->v][t] = dis[u][t] + p->c[t];
    dfs1(p->v, u, mini);
  }
}
void dfs2(int u, int pa, int mini) {
  cro[u] = min(cro[u],
               dis[u][0] + dis[u][1] + dis[mini][0] + dis[mini][1] + a[mini]);
  for (Edge *p = h[u]; p; p = p->next) {
    if (p->v == pa || vis[p->v]) continue;
    dfs2(p->v, u, mini);
  }
}
void work(int u) {
  int mini = u;
  dis[u][0] = dis[u][1] = 0;
  dfs1(u, -1, mini);
  dfs2(u, -1, mini);
}
void solve(int u) {
  work(u);
  vis[u] = 1;
  int root;
  for (Edge *p = h[u]; p; p = p->next) {
    if (vis[p->v]) continue;
    root = 0;
    getroot(p->v, u, size[p->v], root);
    solve(root);
  }
}
int dep[MAXN], anc[MAXN][MAXK];
long long ever[MAXN][2][2][MAXK];
void dfs(int u, int pa) {
  for (int i = 1; i < MAXK; i++) {
    anc[u][i] = anc[anc[u][i - 1]][i - 1];
    for (int ti = 0; ti <= 1; ++ti)
      for (int tj = 0; tj <= 1; ++tj) {
        ever[u][ti][tj][i] = INF;
        for (int tk = 0; tk <= 1; ++tk)
          ever[u][ti][tj][i] =
              min(ever[u][ti][tj][i],
                  ever[u][ti][tk][i - 1] + ever[anc[u][i - 1]][tk][tj][i - 1]);
      }
  }
  for (Edge *p = h[u]; p; p = p->next) {
    if (p->v == pa) continue;
    dep[p->v] = dep[u] + 1;
    anc[p->v][0] = u;
    for (int ti = 0; ti <= 1; ++ti)
      for (int tj = 0; tj <= 1; ++tj)
        if (ti == tj)
          ever[p->v][ti][tj][0] =
              min(p->c[ti], p->c[ti ^ 1] + cro[u] + cro[p->v]);
        else
          ever[p->v][ti][tj][0] = min(p->c[ti] + cro[u], p->c[tj] + cro[p->v]);
    dfs(p->v, u);
  }
}
long long jump(int u, int tu, int v, int tv) {
  if (dep[u] < dep[v]) swap(u, v), swap(tu, tv);
  int t = dep[u] - dep[v];
  long long cur[2];
  cur[tu] = 0;
  cur[tu ^ 1] = cro[u];
  long long tmp[2];
  for (int i = 0; i < MAXK; i++)
    if ((1 << i) & t) {
      tmp[0] = tmp[1] = INF;
      for (int ti = 0; ti <= 1; ++ti)
        for (int tj = 0; tj <= 1; ++tj) {
          tmp[tj] = min(tmp[tj], cur[ti] + ever[u][ti][tj][i]);
        }
      cur[0] = tmp[0];
      cur[1] = tmp[1];
      u = anc[u][i];
    }
  if (u == v) return cur[tv];
  long long cvr[2];
  cvr[tv] = 0;
  cvr[tv ^ 1] = cro[v];
  for (int i = MAXK - 1; i >= 0; i--) {
    if (anc[u][i] == anc[v][i]) continue;
    tmp[0] = tmp[1] = INF;
    for (int ti = 0; ti <= 1; ++ti)
      for (int tj = 0; tj <= 1; ++tj)
        tmp[tj] = min(tmp[tj], cur[ti] + ever[u][ti][tj][i]);
    cur[0] = tmp[0];
    cur[1] = tmp[1];
    u = anc[u][i];
    tmp[0] = tmp[1] = INF;
    for (int ti = 0; ti <= 1; ++ti)
      for (int tj = 0; tj <= 1; ++tj)
        tmp[tj] = min(tmp[tj], cvr[ti] + ever[v][ti][tj][i]);
    cvr[0] = tmp[0];
    cvr[1] = tmp[1];
    v = anc[v][i];
  }
  tmp[0] = tmp[1] = INF;
  for (int ti = 0; ti <= 1; ++ti)
    for (int tj = 0; tj <= 1; ++tj)
      tmp[tj] = min(tmp[tj], cur[ti] + ever[u][ti][tj][0]);
  cur[0] = tmp[0];
  cur[1] = tmp[1];
  tmp[0] = tmp[1] = INF;
  for (int ti = 0; ti <= 1; ++ti)
    for (int tj = 0; tj <= 1; ++tj)
      tmp[tj] = min(tmp[tj], cvr[ti] + ever[v][ti][tj][0]);
  cvr[0] = tmp[0];
  cvr[1] = tmp[1];
  return min(cur[0] + cvr[0], cur[1] + cvr[1]);
}
int main() {
  int Q, u, v;
  long long x, y;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%lld", &a[i]);
  for (int i = 1; i < n; i++) {
    scanf("%d%d%lld%lld", &u, &v, &x, &y);
    addEdge(h, u, v, x, y);
    addEdge(h, v, u, x, y);
  }
  memset(cro, 0x3f, sizeof(cro));
  getroot(1, -1, n, u);
  solve(u);
  dfs(1, -1);
  scanf("%d", &Q);
  while (Q--) {
    scanf("%d%d", &u, &v);
    int tu = !(u & 1), tv = !(v & 1);
    u = ((u - 1) >> 1) + 1;
    v = ((v - 1) >> 1) + 1;
    printf("%lld\n", jump(u, tu, v, tv));
  }
  return 0;
}