#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize(0)
const int N = 400010;
const int inf = 0x3f3f3f3f;
struct SegmentTree {
  vector<int> c;
  int siz;
  void modify(int pos, int val, int l, int r, int k) {
    c[k] = min(val, c[k]);
    if (l == r) return;
    int mid = (l + r) >> 1;
    if (pos <= mid)
      modify(pos, val, l, mid, k << 1);
    else
      modify(pos, val, mid + 1, r, k << 1 | 1);
  }
  int query(int L, int R, int l, int r, int k) {
    if (l >= L && r <= R) return c[k];
    int ans = inf, mid = (l + r) >> 1;
    if (L <= mid) ans = min(ans, query(L, R, l, mid, k << 1));
    if (R > mid) ans = min(ans, query(L, R, mid + 1, r, k << 1 | 1));
    return ans;
  }
  void resize(int x) {
    siz = x;
    c.clear();
    c.resize(x * 4 + 1, inf);
  }
  void modify(int pos, int val) { modify(pos, val, 1, siz, 1); }
  int query(int l, int r) { return query(l, r, 1, siz, 1); }
} T;
struct Query {
  int r1, c1, r2, c2, id;
} qry[N];
bool cmp1(Query x, Query y) { return x.r2 < y.r2; }
bool cmp2(Query x, Query y) { return x.r1 < y.r1; }
int a[N], ans[N], c[N], n, q;
vector<Query> qrys;
void solve() {
  qrys.clear();
  for (int i = 1; i <= q; ++i) {
    if (qry[i].r2 >= qry[i].r1) qrys.push_back(qry[i]);
  }
  vector<int> stk, stkval;
  stk.push_back(0);
  stkval.push_back(-inf);
  sort(qrys.begin(), qrys.end(), cmp1);
  vector<Query>::iterator itList = qrys.begin();
  for (int i = 1; i <= n; ++i) {
    while (a[i] < stkval.back()) stk.pop_back(), stkval.pop_back();
    stk.push_back(i);
    stkval.push_back(a[i]);
    while (itList != qrys.end() && itList->r2 == i) {
      int now = itList->id, r1 = itList->r1, r2 = itList->r2, c1 = itList->c1,
          c2 = itList->c2;
      vector<int>::iterator l = lower_bound(stk.begin(), stk.end(), r1);
      vector<int>::iterator lval = stkval.begin() + (l - stk.begin());
      c[now] = *lval;
      ans[now] = min(ans[now], abs(r1 - r2) + abs(min(c[now], c1) - c2));
      int tmp1 = abs((*lower_bound(lval, stkval.end(), c2)) - c2);
      vector<int>::iterator tmp = upper_bound(lval, stkval.end(), c2);
      int tmp2 = tmp != lval ? abs((*(--tmp)) - c2) : inf;
      ans[now] = min(ans[now], abs(r1 - r2) + min(tmp1, tmp2) + 1);
      itList++;
    }
  }
  sort(qrys.rbegin(), qrys.rend(), cmp1);
  T.resize(n);
  stk.clear();
  stkval.clear();
  stk.push_back(n + 1);
  stkval.push_back(-inf);
  itList = qrys.begin();
  for (int i = n; i >= 1; --i) {
    while (a[i] < stkval.back()) stk.pop_back(), stkval.pop_back();
    stk.push_back(i);
    stkval.push_back(a[i]);
    T.modify(i, a[i] + 2 * i);
    while (itList != qrys.end() && itList->r2 == i) {
      int now = itList->id, r1 = itList->r1, r2 = itList->r2,
          c1 = min(c[now], itList->c1), c2 = itList->c2;
      vector<int>::iterator lval =
          upper_bound(stkval.begin(), stkval.end(), c2);
      vector<int>::iterator l = stk.begin() + (lval - stkval.begin());
      lval--;
      l--;
      ans[now] = min(ans[now], abs(r1 - r2) + c2 - (*lval) + 2 * ((*l) - i) +
                                   (((*lval) > c1)));
      lval++;
      l++;
      vector<int>::iterator dval =
          --upper_bound(stkval.begin(), stkval.end(), c1);
      vector<int>::iterator d = stk.begin() + (dval - stkval.begin());
      if (l <= d)
        ans[now] = min(ans[now], abs(r1 - r2) + T.query(*d, *l) - i * 2 - c2);
      dval++;
      d++;
      if (l != stk.end() && d != stk.end())
        ans[now] = min(ans[now],
                       abs(r1 - r2) + T.query(i, *max(l, d)) - i * 2 - c2 + 1);
      itList++;
    }
  }
  sort(qrys.begin(), qrys.end(), cmp2);
  T.resize(n);
  stk.clear();
  stkval.clear();
  stk.push_back(n + 1);
  stkval.push_back(-inf);
  itList = qrys.begin();
  for (int i = 1; i <= n; ++i) {
    while (a[i] < stkval.back()) stkval.pop_back(), stk.pop_back();
    stk.push_back(i);
    stkval.push_back(a[i]);
    T.modify(i, a[i] - i * 2);
    while (itList != qrys.end() && itList->r1 == i) {
      int now = itList->id, r1 = itList->r1, r2 = itList->r2,
          c1 = min(c[now], itList->c1), c2 = itList->c2;
      vector<int>::iterator eval =
          --upper_bound(stkval.begin(), stkval.end(), c[now]);
      vector<int>::iterator e = stk.begin() + (eval - stkval.begin());
      vector<int>::iterator lval =
          upper_bound(stkval.begin(), stkval.end(), c2);
      vector<int>::iterator l = stk.begin() + (lval - stkval.begin());
      lval--;
      l--;
      if (l <= e)
        ans[now] = min(ans[now], abs(r1 - r2) + c2 - (*lval) + 2 * (i - (*l)) +
                                     ((*lval) > c1));
      lval++;
      l++;
      vector<int>::iterator dval =
          --upper_bound(stkval.begin(), stkval.end(), c1);
      vector<int>::iterator d = stk.begin() + (dval - stkval.begin());
      if (l <= min(d, e))
        ans[now] =
            min(ans[now], abs(r1 - r2) + T.query(*l, *min(d, e)) + i * 2 - c2);
      dval++;
      d++;
      if (max(l, d) <= e)
        ans[now] = min(ans[now],
                       abs(r1 - r2) + T.query(*max(l, d), *e) + i * 2 - c2 + 1);
      itList++;
    }
  }
}
void reverse() {
  reverse(a + 1, a + 1 + n);
  for (int i = 1; i <= q; ++i) {
    qry[i].r1 = n - qry[i].r1 + 1;
    qry[i].r2 = n - qry[i].r2 + 1;
  }
}
int read() {
  int x = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -f;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = x * 10 + c - 48;
    c = getchar();
  }
  return x * f;
}
signed main() {
  n = read();
  for (int i = 1; i <= n; ++i) a[i] = read();
  q = read();
  for (int i = 1; i <= q; ++i) {
    qry[i].r1 = read(), qry[i].c1 = read(), qry[i].r2 = read(),
    qry[i].c2 = read();
    qry[i].id = i;
    ans[i] = qry[i].c2 + abs(qry[i].r1 - qry[i].r2) + 1;
  }
  solve();
  reverse();
  solve();
  for (int i = 1; i <= q; ++i) printf("%d\n", ans[i]);
  fclose(stdin);
  fclose(stdout);
  return 0;
}
