#include <bits/stdc++.h>
using namespace std;
const int N = 400010;
int read() {
  char c = getchar();
  int d = 0, f = 1;
  for (; c < '0' || c > '9'; c = getchar())
    if (c == '-') f = -1;
  for (; c >= '0' && c <= '9'; d = d * 10 + c - 48, c = getchar())
    ;
  return d * f;
}
struct st {
  int n, t[N], a[N], F[N][20];
  void init(int* _a, int _n) {
    n = 0;
    memset(t, 0, sizeof t);
    memset(a, 0, sizeof a);
    n = _n;
    for (int i = 1; i <= n; ++i) a[i] = _a[i];
    for (int i = 2; i <= n; ++i) t[i] = t[i >> 1] + 1;
    for (int i = 1; i <= n; ++i) F[i][0] = a[i];
    for (int i = 1; i <= n; ++i)
      for (int j = 1; j <= t[i]; ++j)
        F[i][j] = min(F[i][j - 1], F[i - (1 << j - 1)][j - 1]);
  }
  int ask(int x, int y) {
    if (x > y) swap(x, y);
    int tt = t[y - x + 1];
    return min(F[x + (1 << tt) - 1][tt], F[y][tt]);
  }
} A, B, C;
int n, a[N], b[N], c[N], m, ans[N], low[N];
struct atom {
  int id, x1, y1, x2, y2;
} q[N];
int FindL(int L, int R, int Z, int v) {
  L--;
  while (L < R) {
    int mid = (L + R + 1) >> 1, s = A.ask(mid, Z);
    if (s <= v)
      L = mid;
    else
      R = mid - 1;
  }
  return L;
}
int FindR(int L, int R, int Z, int v) {
  R++;
  while (L < R) {
    int mid = (L + R) >> 1, s = A.ask(Z, mid);
    if (s <= v)
      R = mid;
    else
      L = mid + 1;
  }
  return L;
}
void work() {
  A.init(a, n);
  for (int i = 1; i <= n; ++i) b[i] = a[i] - i * 2, c[i] = a[i] + i * 2;
  B.init(b, n);
  C.init(c, n);
  for (int i = 1; i <= m; ++i)
    if (q[i].x1 <= q[i].x2) {
      int x1 = q[i].x1, y1 = q[i].y1, x2 = q[i].x2, y2 = q[i].y2;
      low[i] = A.ask(x1, x2);
      ans[i] = min(x2 - x1 + abs(y2 - min(y1, low[i])), x2 - x1 + 1 + y2);
      int L = FindL(x1, x2, x2, y2), L1, tmp;
      if (L + 1 <= x2) tmp = abs(y2 - A.ask(L + 1, x2));
      if (L >= x1) tmp = min(tmp, abs(y2 - a[L]));
      ans[i] = min(ans[i], x2 - x1 + 1 + tmp);
      assert(ans[i] >= 0);
      if (x1 > 1 && y2 < low[i]) {
        L = FindL(1, x1 - 1, x2, y2);
        L1 = FindL(1, x1 - 1, x2, y1);
        if (L > 0)
          ans[i] = min(ans[i], x1 + x2 - L * 2 + abs(y2 - a[L]) + (a[L] > y1));
        int tmp = 1e9;
        if (L1 <= L)
          tmp = B.ask(L + 1, x1) + 1;
        else
          tmp = min(B.ask(L + 1, L1), B.ask(L1 + 1, x1) + 1);
        ans[i] = min(ans[i], x1 + x2 - y2 + tmp);
        if (L < x1 - 1) assert(A.ask(L + 1, x2) >= y2);
      }
      if (x2 < n) {
        L = FindR(x2 + 1, n, x2, y2);
        int Y1 = min(low[i], y1);
        L1 = FindR(x2 + 1, n, x2, min(low[i], Y1));
        if (L <= n)
          ans[i] = min(ans[i], L * 2 - x1 - x2 + abs(y2 - a[L]) + (a[L] > Y1));
        int tmp = 1e9;
        if (L1 >= L)
          tmp = C.ask(x2, L - 1) + 1;
        else
          tmp = min(C.ask(x2, L1 - 1) + 1, C.ask(L1, L - 1));
        ans[i] = min(ans[i], -x1 - x2 - y2 + tmp);
        assert(A.ask(x2, L - 1) >= y2);
      }
    }
}
int main() {
  n = read();
  for (int i = 1; i <= n; ++i) a[i] = read();
  m = read();
  for (int i = 1; i <= m; ++i)
    q[i].x1 = read(), q[i].y1 = read(), q[i].x2 = read(), q[i].y2 = read(),
    q[i].id = i;
  work();
  reverse(a + 1, a + n + 1);
  for (int i = 1; i <= m; ++i)
    q[i].x1 = n + 1 - q[i].x1, q[i].x2 = n + 1 - q[i].x2;
  for (int i = 1; i <= m; ++i)
    if (q[i].x1 == q[i].x2) q[i].x1++;
  work();
  for (int i = 1; i <= m; ++i) printf("%d\n", ans[i]);
}
