Dreamoon has just created a document of hard problems using notepad.exe. The document consists of n lines of text, ai denotes the length of the i-th line. He now wants to know what is the fastest way to move the cursor around because the document is really long.

Let (r, c) be a current cursor position, where r is row number and c is position of cursor in the row. We have 1 ≤ r ≤ n and 0 ≤ c ≤ ar.

We can use following six operations in notepad.exe to move our cursor assuming the current cursor position is at (r, c):

  1. up key: the new cursor position (nr, nc) = (max(r - 1, 1), min(anr, c))
  2. down key: the new cursor position (nr, nc) = (min(r + 1, n), min(anr, c))
  3. left key: the new cursor position (nr, nc) = (r, max(0, c - 1))
  4. right key: the new cursor position (nr, nc) = (r, min(anr, c + 1))
  5. HOME key: the new cursor position (nr, nc) = (r, 0)
  6. END key: the new cursor position (nr, nc) = (r, ar)



You're given the document description (n and sequence ai) and q queries from Dreamoon. Each query asks what minimal number of key presses is needed to move the cursor from (r1, c1) to (r2, c2).

Input

The first line contains an integer n(1 ≤ n ≤ 400, 000) — the number of lines of text. 

The second line contains n integers a1, a2, ..., an(1 ≤ ai ≤ 108).

The third line contains an integer q(1 ≤ q ≤ 400, 000). 

Each of the next q lines contains four integers r1, c1, r2, c2 representing a query (1 ≤ r1, r2 ≤ n, 0 ≤ c1 ≤ ar1, 0 ≤ c2 ≤ ar2).

Output

For each query print the result of the query.

Examples

Input

9
1 3 5 3 1 3 5 3 1
4
3 5 3 1
3 3 7 3
1 0 3 3
6 0 7 3


Output

2
5
3
2


Input

2
10 5
1
1 0 1 5


Output

3

Note

In the first sample, the first query can be solved with keys: HOME, right.

The second query can be solved with keys: down, down, down, END, down.

The third query can be solved with keys: down, END, down.

The fourth query can be solved with keys: END, down.
#include <bits/stdc++.h>
using namespace std;
int Ans[400005], n, m;
int a[400005], b[400005], W[400005], top;
int lc[800005], rc[800005], f[3][800005], rt;
struct O {
  int p, q, x, y, i;
} o[400005];
bool cmo(O a, O b) { return a.x < b.x; }
void build(int &u, int p, int q) {
  u = ++top;
  f[1][u] = f[2][u] = 1000000000;
  if (p == q) {
    f[0][u] = W[p];
    return;
  }
  build(lc[u], p, (p + q) / 2);
  build(rc[u], (p + q) / 2 + 1, q);
  f[0][u] = min(f[0][lc[u]], f[0][rc[u]]);
}
void mody(int u, int p, int q, int k) {
  if (p == q) {
    f[1][u] = b[p] - 2 * a[p];
    f[2][u] = -b[p] - 2 * a[p];
    return;
  }
  if (k <= (p + q) / 2)
    mody(lc[u], p, (p + q) / 2, k);
  else
    mody(rc[u], (p + q) / 2 + 1, q, k);
  f[1][u] = min(f[1][lc[u]], f[1][rc[u]]);
  f[2][u] = min(f[2][lc[u]], f[2][rc[u]]);
}
int qmin(int I, int u, int p, int q, int l, int r) {
  if (l <= p && q <= r) return f[I][u];
  int tmp = 1000000000;
  if (l <= (p + q) / 2) tmp = qmin(I, lc[u], p, (p + q) / 2, l, r);
  if (r > (p + q) / 2) tmp = min(tmp, qmin(I, rc[u], (p + q) / 2 + 1, q, l, r));
  return tmp;
}
void go(O o, int L, int R) {
  if (L > R) return;
  int k1 = upper_bound(b + L, b + R + 1, o.q) - b;
  int k2 = lower_bound(b + L, b + R + 1, o.y) - b;
  if (k1 > k2) swap(k1, k2);
  int ans;
  if (L <= k1 - 1) {
    ans = o.q < b[L];
    if (b[L] < o.y)
      ans += o.y + o.x + o.p + qmin(2, 1, 1, n, L, k1 - 1);
    else
      ans += o.x + o.p - o.y + qmin(1, 1, 1, n, L, k1 - 1);
    Ans[o.i] = min(Ans[o.i], ans);
  }
  if (k1 <= k2 - 1) {
    ans = o.q < b[k1];
    if (b[k1] < o.y)
      ans += o.y + o.x + o.p + qmin(2, 1, 1, n, k1, k2 - 1);
    else
      ans += o.x + o.p - o.y + qmin(1, 1, 1, n, k1, k2 - 1);
    Ans[o.i] = min(Ans[o.i], ans);
  }
  if (k2 <= R) {
    ans = o.q < b[k2];
    if (b[k2] < o.y)
      ans += o.y + o.x + o.p + qmin(2, 1, 1, n, k2, R);
    else
      ans += o.x + o.p - o.y + qmin(1, 1, 1, n, k2, R);
    Ans[o.i] = min(Ans[o.i], ans);
  }
}
void solve() {
  top = 0;
  for (int i = 1, j = 1; i <= n && j <= m; ++i) {
    while (top && b[top] >= W[i]) --top;
    a[++top] = i;
    b[top] = W[i];
    mody(1, 1, n, top);
    for (; j <= m && o[j].x == i; ++j)
      if (o[j].p <= o[j].x) {
        int k = lower_bound(a + 1, a + top + 1, o[j].p) - a;
        go(o[j], 1, k - 1);
        int q = min(o[j].q, b[k]);
        int t = lower_bound(b + k, b + top + 1, o[j].y) - b;
        if (t <= top)
          Ans[o[j].i] = min(Ans[o[j].i], o[j].x - o[j].p + abs(b[t] - o[j].y) +
                                             (int)(q < b[t]));
        if (--t >= k)
          Ans[o[j].i] = min(Ans[o[j].i], o[j].x - o[j].p + abs(b[t] - o[j].y) +
                                             (int)(q < b[t]));
        Ans[o[j].i] = min(Ans[o[j].i], o[j].x - o[j].p + abs(q - o[j].y));
      } else {
        int tmp = o[j].q;
        o[j].q = min(tmp, qmin(0, 1, 1, n, o[j].x, o[j].p));
        go(o[j], 1, top);
        o[j].q = tmp;
      }
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d", &W[i]);
  scanf("%d", &m);
  for (int i = 1; i <= m; ++i) {
    scanf("%d%d%d%d", &o[i].p, &o[i].q, &o[i].x, &o[i].y);
    o[i].i = i;
    Ans[i] = abs(o[i].x - o[i].p) + 1 + o[i].y;
  }
  sort(o + 1, o + m + 1, cmo);
  top = 0;
  build(rt, 1, n);
  solve();
  for (int i = 1; i <= n / 2; ++i) swap(W[i], W[n - i + 1]);
  for (int i = 1; i <= m / 2; ++i) swap(o[i], o[m - i + 1]);
  for (int i = 1; i <= m; ++i) o[i].x = n - o[i].x + 1, o[i].p = n - o[i].p + 1;
  top = 0;
  build(rt, 1, n);
  solve();
  for (int i = 1; i <= m; ++i) printf("%d\n", Ans[i]);
  return 0;
}
