#include <bits/stdc++.h>
using namespace std;
int n, m, a[400100], stk[400100], res[400100], tp;
struct Query {
  int x1, x2, _19260817, _17680321, id;
  Query(int i) { scanf("%d%d%d%d", &x1, &_19260817, &x2, &_17680321), id = i; }
  friend bool operator<(const Query &x, const Query &y) { return x.x2 < y.x2; }
};
int cnt, rt;
struct Treap {
  int ch[2], sz, val, pos, mnp, mnm, rd;
} t[400100];
void pushup(int x) {
  t[x].mnp = t[x].val - 2 * t[x].pos;
  t[x].mnm = -t[x].val - 2 * t[x].pos;
  t[x].sz = 1;
  if (t[x].ch[0])
    t[x].mnp = min(t[x].mnp, t[t[x].ch[0]].mnp),
    t[x].mnm = min(t[x].mnm, t[t[x].ch[0]].mnm), t[x].sz += t[t[x].ch[0]].sz;
  if (t[x].ch[1])
    t[x].mnp = min(t[x].mnp, t[t[x].ch[1]].mnp),
    t[x].mnm = min(t[x].mnm, t[t[x].ch[1]].mnm), t[x].sz += t[t[x].ch[1]].sz;
}
int merge(int x, int y) {
  if (!x || !y) return x + y;
  if (t[x].rd > t[y].rd) {
    t[x].ch[1] = merge(t[x].ch[1], y), pushup(x);
    return x;
  } else {
    t[y].ch[0] = merge(x, t[y].ch[0]), pushup(y);
    return y;
  }
}
void splitbypos(int x, int k, int &u, int &v) {
  if (!x) {
    u = v = 0;
    return;
  }
  if (t[x].pos < k)
    u = x, splitbypos(t[x].ch[1], k, t[x].ch[1], v);
  else
    v = x, splitbypos(t[x].ch[0], k, u, t[x].ch[0]);
  pushup(x);
}
void splitbyval(int x, int k, int &u, int &v) {
  if (!x) {
    u = v = 0;
    return;
  }
  if (t[x].val < k)
    u = x, splitbyval(t[x].ch[1], k, t[x].ch[1], v);
  else
    v = x, splitbyval(t[x].ch[0], k, u, t[x].ch[0]);
  pushup(x);
}
void splitbysize(int x, int k, int &u, int &v) {
  if (!x) {
    u = v = 0;
    return;
  }
  if (t[t[x].ch[0]].sz >= k)
    v = x, splitbysize(t[x].ch[0], k, u, t[x].ch[0]);
  else
    u = x, splitbysize(t[x].ch[1], k - t[t[x].ch[0]].sz - 1, t[x].ch[1], v);
  pushup(x);
}
int newnode(int x) {
  int u = ++cnt;
  t[u].ch[0] = t[u].ch[1] = 0;
  t[u].pos = x, t[u].val = a[x];
  t[u].rd = rand() * rand();
  pushup(u);
  return u;
}
void Insert(int x) {
  int a, b;
  splitbypos(rt, x, a, b);
  rt = merge(merge(a, newnode(x)), b);
}
void Delete(int x) {
  int a, b, c;
  splitbypos(rt, x, a, b);
  splitbysize(b, 1, b, c);
  rt = merge(a, c);
}
int Ask(int bef, int x, int now) {
  int a, b, c, e, f;
  splitbysize(rt, bef - 1, b, c);
  splitbyval(b, x, a, b);
  int ret = 0x3f3f3f3f;
  splitbyval(a, now + 1, e, f);
  ret = min(ret, min(t[e].mnm + x, t[f].mnm + x + 1));
  a = merge(e, f);
  splitbyval(b, now + 1, e, f);
  ret = min(ret, min(t[e].mnp - x, t[f].mnp - x + 1));
  b = merge(e, f);
  rt = merge(merge(a, b), c);
  return ret;
}
void Iterate(int x) {
  if (!x) return;
  Iterate(t[x].ch[0]);
  printf("[%d:%d]", x, a[x]);
  Iterate(t[x].ch[1]);
}
void func(vector<Query> &v) {
  sort(v.begin(), v.end());
  tp = 0;
  cnt = rt = 0;
  for (int i = 0, j = 1; i < v.size(); i++) {
    while (j <= v[i].x2) {
      while (tp && a[stk[tp]] > a[j]) Delete(stk[tp--]);
      Insert(stk[++tp] = j++);
    }
    int tmp = lower_bound(stk + 1, stk + tp + 1, v[i].x1) - stk;
    int fin = min(v[i]._19260817, a[stk[tmp]]);
    res[v[i].id] =
        min(res[v[i].id], abs(v[i].x1 - v[i].x2) + abs(fin - v[i]._17680321));
    res[v[i].id] =
        min(res[v[i].id], abs(v[i].x1 - v[i].x2) + v[i]._17680321 + 1);
    a[n + 1] = v[i]._17680321;
    int pmt = lower_bound(stk + tmp, stk + tp + 1, n + 1,
                          [](int u, int v) { return a[u] < a[v]; }) -
              stk;
    res[v[i].id] = min(res[v[i].id], abs(v[i].x1 - v[i].x2) +
                                         abs(a[stk[pmt]] - v[i]._17680321) + 1);
    if (pmt > tmp)
      res[v[i].id] =
          min(res[v[i].id], abs(v[i].x1 - v[i].x2) +
                                abs(a[stk[pmt - 1]] - v[i]._17680321) + 1);
    res[v[i].id] =
        min(res[v[i].id],
            v[i].x2 + v[i].x1 + Ask(tmp, v[i]._17680321, v[i]._19260817));
    v[i]._19260817 = fin;
  }
  tp = 0;
  cnt = rt = 0;
  reverse(v.begin(), v.end());
  for (int i = 0; i < v.size(); i++)
    v[i].x1 = n - v[i].x1 + 1, v[i].x2 = n - v[i].x2 + 1;
  reverse(a + 1, a + n + 1);
  for (int i = 0, j = 1; i < v.size(); i++) {
    while (j <= v[i].x2) {
      while (tp && a[stk[tp]] > a[j]) Delete(stk[tp--]);
      Insert(stk[++tp] = j++);
    }
    res[v[i].id] =
        min(res[v[i].id], abs(v[i].x1 - v[i].x2) + 2 * v[i].x2 +
                              Ask(tp + 1, v[i]._17680321, v[i]._19260817));
  }
  reverse(a + 1, a + n + 1);
}
vector<Query> v1, v2;
int main() {
  scanf("%d", &n), memset(res, 0x3f, sizeof(res)),
      t[0].mnm = t[0].mnp = 0x3f3f3f3f;
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  scanf("%d", &m);
  for (int i = 1; i <= m; i++) {
    Query q(i);
    if (q.x1 <= q.x2)
      v1.push_back(q);
    else
      q.x1 = n - q.x1 + 1, q.x2 = n - q.x2 + 1, v2.push_back(q);
  }
  func(v1);
  reverse(a + 1, a + n + 1);
  func(v2);
  for (int i = 1; i <= m; i++) printf("%d\n", res[i]);
  return 0;
}
