#include <bits/stdc++.h>
using namespace std;
const int N = 4e5 + 5;
int n, q, lg[N], f[22][N], c[N], r1[N], r2[N], c1[N], c2[N], a[N], mn[N], s[N],
    pre[N], suf[N], w, u;
struct Node {
  int x, y;
  friend bool operator<(const Node &a, const Node &b) { return a.x < b.x; }
} Q[N + N];
struct cmp {
  inline bool operator()(const int &x, const int &y) { return a[x] < a[y]; }
};
inline bool check(int x, int y) {
  if (!~x) return 0;
  if (!~y) return 1;
  if (a[x] - x - x != a[y] - y - y) return a[x] - x - x < a[y] - y - y;
  return a[x] < a[y];
}
inline void move() {
  int t = 1;
  w = u = 0;
  for (int i = 1; i <= q; ++i) {
    Q[++w] = {min(r1[i], r2[i]), i};
    if (r1[i] < r2[i]) Q[++w] = {r2[i], i};
  }
  sort(Q + 1, Q + 1 + w), pre[0] = 0x3f3f3f3f, suf[0] = 0;
  for (int i = 1; i <= n; ++i) {
    while (u && a[i] <= a[c[u]]) --u;
    c[++u] = i, pre[u] = min(pre[u - 1], -a[i] - i - i);
    while (suf[0] && check(i, suf[suf[0]])) --suf[0];
    suf[++suf[0]] = i;
    while (t <= w && Q[t].x == i) {
      int x = Q[t].y;
      if (min(r1[x], r2[x]) == i)
        if (r1[x] > r2[x] || a[mn[x]] >= c2[x]) {
          int y = c1[x];
          a[0] = c2[x];
          if (r1[x] > r2[x]) y = min(y, a[mn[x]]);
          int id = upper_bound(c + 1, c + 1 + u, 0, cmp()) - c - 1;
          s[x] = min(s[x], r1[x] + pre[id] + r2[x] + c2[x] + (y < a[c[id]])),
          a[0] = c2[x];
          int Id = lower_bound(suf + 1, suf + 1 + suf[0], 0, cmp()) - suf;
          if (Id <= suf[0])
            Id = suf[Id], s[x] = min(s[x], r1[x] + a[Id] - Id - Id + r2[x] -
                                               c2[x] + (y < a[Id]));
        }
      if (r1[x] <= r2[x] && r2[x] == i) {
        a[0] = max(a[mn[x]], c2[x]);
        int id = lower_bound(c + 1, c + 1 + u, 0, cmp()) - c;
        for (int j = -1; j < 2; ++j)
          if (c[id + j] >= mn[x] && id + j <= u)
            s[x] = min(s[x], r2[x] - r1[x] +
                                 (min(c1[x], a[mn[x]]) < a[c[id + j]]) +
                                 abs(a[c[id + j]] - c2[x]));
      }
      ++t;
    }
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d", a + i);
  scanf("%d", &q);
  for (int i = 1; i <= q; ++i)
    scanf("%d%d%d%d", r1 + i, c1 + i, r2 + i, c2 + i);
  memset(s, 63, sizeof s);
  for (int i = 2; i <= n; ++i) lg[i] = lg[i >> 1] + 1;
  for (int i = 1; i <= n; ++i) f[0][i] = i;
  for (int i = 1; i <= lg[n] + 1; ++i)
    for (int j = 1; j <= n - (1 << i) + 1; ++j)
      f[i][j] = a[f[i - 1][j]] < a[f[i - 1][j + (1 << i - 1)]]
                    ? f[i - 1][j]
                    : f[i - 1][j + (1 << i - 1)];
  for (int i = 1; i <= q; ++i) {
    int l = min(r1[i], r2[i]), r = max(r1[i], r2[i]), k = lg[r - l + 1],
        p = a[f[k][l]] < a[f[k][r - (1 << k) + 1]] ? f[k][l]
                                                   : f[k][r - (1 << k) + 1];
    mn[i] = p;
    if (a[p] >= c1[i] && a[p] >= c2[i])
      s[i] = min(s[i], abs(r1[i] - r2[i]) + abs(c1[i] - c2[i]));
  }
  move(), reverse(a + 1, a + 1 + n);
  for (int i = 1; i <= q; ++i)
    r1[i] = n - r1[i] + 1, r2[i] = n - r2[i] + 1, mn[i] = n - mn[i] + 1;
  move();
  for (int i = 1; i <= q; ++i)
    printf("%d\n", min(s[i], abs(r1[i] - r2[i]) + c2[i] + 1));
  return 0;
}
