#include <bits/stdc++.h>
using namespace std;
long long ans[400010];
class query {
 public:
  int l, r, c1, c2, id, bas;
};
int n, lg2[400010];
class solver {
 public:
  int a[400010];
  vector<query> q, qp[400010];
  int mn[1600010];
  void modify(int p, int l, int r, int pos, int v) {
    if (l == r) {
      mn[p] = v;
      return;
    }
    int mid = (l + r) >> 1;
    if (pos <= mid)
      modify((p << 1), l, mid, pos, v);
    else
      modify(((p << 1) | 1), mid + 1, r, pos, v);
    mn[p] = min(mn[(p << 1)], mn[((p << 1) | 1)]);
  }
  int query(int p, int l, int r, int ql, int qr) {
    if (ql <= l && r <= qr) return mn[p];
    int ret = 0x3f3f3f3f, mid = (l + r) >> 1;
    if (ql <= mid) ret = query((p << 1), l, mid, ql, qr);
    if (qr > mid) ret = min(ret, query(((p << 1) | 1), mid + 1, r, ql, qr));
    return ret;
  }
  void pre() {
    for (int i = 1; i <= n; i++) qp[i].clear();
    for (auto &x : q) qp[x.r].push_back(x);
  }
  void solve() {
    for (auto &x : q)
      ans[x.id] = min(ans[x.id], x.bas + 1ll + x.r - x.l + x.c2);
    vector<pair<int, int> > stk;
    stk.push_back(make_pair(0, 0));
    modify(1, 0, n, 0, 0x3f3f3f3f);
    for (int i = 1; i <= n; i++) {
      while (!stk.empty() && stk.back().first >= a[i]) stk.pop_back();
      stk.push_back(make_pair(a[i], i));
      modify(1, 0, n, stk.size() - 1, a[i] - 2 * i);
      for (auto &x : qp[i]) {
        int l = 1, r = stk.size() - 1, pos = 0;
        while (l <= r) {
          int mid = (l + r) >> 1;
          if (stk[mid].second >= x.l)
            pos = mid, r = mid - 1;
          else
            l = mid + 1;
        }
        int pp = pos - 1;
        ans[x.id] = min(ans[x.id], (long long)x.bas + x.r - x.l +
                                       abs(x.c2 - min(x.c1, stk[pos].first)));
        l = pos, r = stk.size() - 1;
        while (l <= r) {
          int mid = (l + r) >> 1;
          if (stk[mid].first <= x.c2)
            pp = mid, l = mid + 1;
          else
            r = mid - 1;
        }
        if (pp != pos - 1)
          ans[x.id] = min(ans[x.id],
                          1ll + x.bas + x.r - x.l + abs(x.c2 - stk[pp].first));
        if (pp != stk.size() - 1)
          ans[x.id] = min(ans[x.id], 1ll + x.bas + x.r - x.l +
                                         abs(x.c2 - stk[pp + 1].first));
        l = 1, r = pos - 1;
        int pos2 = 0;
        while (l <= r) {
          int mid = (l + r) >> 1;
          if (stk[mid].first <= x.c2)
            pos2 = mid, l = mid + 1;
          else
            r = mid - 1;
        }
        if (pos2 > 0)
          ans[x.id] =
              min(ans[x.id], (long long)x.bas + (x.c1 < stk[pos2].first) + x.l +
                                 x.r - 2 * stk[pos2].second +
                                 abs(x.c2 - stk[pos2].first));
        l = pos2 + 1, r = pos - 1;
        int pos3 = pos2;
        while (l <= r) {
          int mid = (l + r) >> 1;
          if (stk[mid].first <= x.c1)
            pos3 = mid, l = mid + 1;
          else
            r = mid - 1;
        }
        if (pos3 >= pos2 + 1)
          ans[x.id] = min(ans[x.id], x.bas + (long long)x.l + x.r +
                                         query(1, 0, n, pos2 + 1, pos3) - x.c2);
        if (pos3 + 1 <= pos - 1)
          ans[x.id] =
              min(ans[x.id], x.bas + (long long)x.l + x.r +
                                 query(1, 0, n, pos3 + 1, pos - 1) - x.c2 + 1);
      }
    }
  }
} s[2];
int a[400010], Q;
int main() {
  scanf("%d", &n);
  for (int i = 2; i <= n; i++) lg2[i] = lg2[i >> 1] + 1;
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  copy(a + 1, a + n + 1, s[0].a + 1);
  copy(a + 1, a + n + 1, s[1].a + 1);
  reverse(s[1].a + 1, s[1].a + n + 1);
  scanf("%d", &Q);
  for (int i = 1; i <= Q; i++) {
    int l, c1, r, c2;
    scanf("%d%d%d%d", &l, &c1, &r, &c2);
    if (l <= r)
      s[0].q.push_back((query){l, r, c1, c2, i, 0});
    else
      s[1].q.push_back((query){n + 1 - l, n + 1 - r, c1, c2, i, 0});
  }
  s[0].pre();
  s[1].pre();
  fill(ans + 1, ans + Q + 1, 0x3f3f3f3f3f3f3f3f);
  vector<query> t[2];
  for (int T = 0; T < 2; T++) {
    vector<pair<int, int> > stk;
    stk.push_back(make_pair(0, 0));
    for (int i = 1; i <= n; i++) {
      while (!stk.empty() && stk.back().first >= s[T].a[i]) stk.pop_back();
      stk.push_back(make_pair(s[T].a[i], i));
      for (auto &x : s[T].qp[i]) {
        int l = 1, r = stk.size() - 1, pos = 0;
        while (l <= r) {
          int mid = (l + r) >> 1;
          if (stk[mid].second >= x.l)
            pos = mid, r = mid - 1;
          else
            l = mid + 1;
        }
        t[T ^ 1].push_back((query){n + 1 - x.r, n + 1 - x.r,
                                   min(x.c1, stk[pos].first), x.c2, x.id,
                                   x.r - x.l});
      }
    }
  }
  s[0].q.insert(s[0].q.end(), t[0].begin(), t[0].end());
  s[1].q.insert(s[1].q.end(), t[1].begin(), t[1].end());
  s[0].pre();
  s[1].pre();
  s[0].solve();
  s[1].solve();
  for (int i = 1; i <= Q; i++) printf("%lld\n", ans[i]);
  return 0;
}
