#include <bits/stdc++.h>
const int N = 4e5 + 10;
template <typename T = int>
inline T read() {
  T x = 0, f = 0;
  char ch = getchar();
  while (!isdigit(ch)) f |= ch == '-', ch = getchar();
  while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
  return f ? -x : x;
}
inline void upd(int &a, int b) { a = std::min(a, b); }
struct Node {
  int r1, c1, r2, c2, id, ans;
} q[N];
struct SegmentTree {
  int Min[N << 2];
  const int inf = 1073741823;
  inline void upd(int k) { Min[k] = std::min(Min[k << 1], Min[k << 1 | 1]); }
  inline void build(int k, int l, int r) {
    if (l == r) return Min[k] = inf, void();
    build(k << 1, l, ((l + r) >> 1)), build(k << 1 | 1, ((l + r) >> 1) + 1, r),
        upd(k);
  }
  inline void Mod(int k, int l, int r, int p, int dat) {
    if (l == r) return Min[k] = dat, void();
    p <= ((l + r) >> 1) ? Mod(k << 1, l, ((l + r) >> 1), p, dat)
                        : Mod(k << 1 | 1, ((l + r) >> 1) + 1, r, p, dat);
    upd(k);
  }
  inline int Ask(int k, int l, int r, int ql, int qr) {
    if (qr < l || r < ql) return inf;
    if (ql <= l && r <= qr) return Min[k];
    return std::min(Ask(k << 1, l, ((l + r) >> 1), ql, qr),
                    Ask(k << 1 | 1, ((l + r) >> 1) + 1, r, ql, qr));
  }
} T1, T2;
int a[N], st[N][21], Log[N], stk[N], top;
inline int Ask(int l, int r) {
  if (l > r) std::swap(l, r);
  int w = Log[r - l + 1];
  return std::min(st[l][w], st[r - (1 << w) + 1][w]);
}
inline int find(int l, int r, int dat) {
  int res = l - 1;
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (a[stk[mid]] <= dat)
      res = mid, l = mid + 1;
    else
      r = mid - 1;
  }
  return res + 1;
}
inline void case_2(Node &q, int val) {
  int ans = abs(std::min(q.c1, val) - q.c2);
  int p1 = std::lower_bound(stk + 1, stk + top + 1, q.r1) - stk;
  int p2 = find(p1, top, q.c2);
  if (p2 - 1 <= top && stk[p2 - 1] >= q.r1)
    ans = std::min(ans, abs(a[stk[p2 - 1]] - q.c2) + 1);
  if (p2 - 0 <= top && stk[p2 - 0] >= q.r1)
    ans = std::min(ans, abs(a[stk[p2 - 0]] - q.c2) + 1);
  upd(q.ans, abs(q.r1 - q.r2) + ans);
}
inline void solve(Node &q, int n) {
  int val = std::min(Ask(q.r1, q.r2), q.c1);
  if (q.r1 <= q.r2) case_2(q, val);
  int ed = std::lower_bound(stk + 1, stk + top + 1, q.r1 + 1) - stk - 1;
  val = std::min(val, q.c1);
  int p1 = find(1, ed, val), p2 = find(1, ed, q.c2);
  if (val >= q.c2) {
    int val1 = T1.Ask(1, 1, n, p2, p1 - 1) - q.c2 + q.r1 + q.r2;
    int val2 = T2.Ask(1, 1, n, 1, p2 - 1) + q.c2 + q.r1 + q.r2;
    upd(q.ans, std::min(val1, val2));
  } else {
    int val1 = T1.Ask(1, 1, n, p2, ed) - q.c2 + q.r1 + q.r2 + 1;
    int val2 = T2.Ask(1, 1, n, p1, p2 - 1) + q.c2 + q.r1 + q.r2 + 1;
    upd(q.ans, std::min(val1, val2));
  }
}
inline void solve(int n, int m) {
  for (int i = 1; i <= n; ++i) st[i][0] = a[i];
  for (int w = 1; w < 19; ++w)
    for (int i = 1; i + (1 << w) - 1 <= n; ++i)
      st[i][w] = std::min(st[i][w - 1], st[i + (1 << w - 1)][w - 1]);
  for (int i = 1; i <= m; ++i) {
    int val = std::min(Ask(q[i].r1, q[i].r2), q[i].c1);
    upd(q[i].ans, abs(q[i].r1 - q[i].r2) + abs(val - q[i].c2));
  }
  std::sort(q + 1, q + m + 1,
            [&](const Node &a, const Node &b) { return a.r2 < b.r2; });
  T1.build(1, 1, n), T2.build(1, 1, n), top = 0;
  int pos = 1;
  for (int i = 1; i <= n; ++i) {
    while (top && a[stk[top]] >= a[i]) --top;
    stk[++top] = i;
    T1.Mod(1, 1, n, top, -2 * i + a[i]);
    T2.Mod(1, 1, n, top, -2 * i - a[i]);
    while (pos <= m && q[pos].r2 == i) solve(q[pos++], n);
  }
}
int main() {
  int n = read();
  Log[0] = -1;
  for (int i = 1; i <= n; ++i) a[i] = read();
  for (int i = 1; i <= n; ++i) Log[i] = Log[i >> 1] + 1;
  int m = read();
  for (int i = 1; i <= m; ++i) {
    q[i].r1 = read(), q[i].c1 = read(), q[i].r2 = read(), q[i].c2 = read();
    q[i].id = i, q[i].ans = abs(q[i].r1 - q[i].r2) + q[i].c2 + 1;
  }
  solve(n, m);
  std::reverse(a + 1, a + n + 1);
  for (int i = 1; i <= m; ++i) {
    q[i].r1 = n - q[i].r1 + 1;
    q[i].r2 = n - q[i].r2 + 1;
  }
  solve(n, m);
  std::sort(q + 1, q + m + 1,
            [&](const Node &a, const Node &b) { return a.id < b.id; });
  for (int i = 1; i <= m; ++i) printf("%d\n", q[i].ans);
  return 0;
}
