#include <bits/stdc++.h>
using namespace std;
struct AskNode {
  int r1, c1, r2, c2, id;
  void read(int _id) {
    scanf("%d%d%d%d", &r1, &c1, &r2, &c2);
    r1--, r2--;
    id = _id;
  }
};
int n, q;
int a[400010];
vector<AskNode> asks[2];
int L[400010][20], R[400010][20], vL[400010][20], vR[400010][20];
int devL[400010], devR[400010], ans[400010];
const int inf = 0x7fffffff;
char s[400010];
void check(int &x, int y, const char *const s) {
  if (x == -1 || x > y) x = y;
}
int getF(int pos, int K, int fa[][20]) {
  for (int i = 0; K; i++, K >>= 1)
    if (K & 1) pos = fa[pos][i];
  return pos;
}
void init() {
  deque<int> que;
  for (int i = 0; i < (n); i++) {
    while (!que.empty() && a[que.back()] >= a[i]) que.pop_back();
    vL[i][0] = a[i] - 2 * i;
    if (que.empty())
      devL[i] = 0;
    else {
      L[i][0] = que.back();
      devL[i] = devL[L[i][0]] + 1;
      for (int k = 1; (1 << k) <= devL[i]; k++) {
        L[i][k] = L[L[i][k - 1]][k - 1];
        vL[i][k] = min(vL[i][k - 1], vL[L[i][k - 1]][k - 1]);
      }
    }
    que.push_back(i);
  }
  while (!que.empty()) que.pop_back();
  for (int i = n - 1; i >= 0; i--) {
    while (!que.empty() && a[que.front()] >= a[i]) que.pop_front();
    vR[i][0] = 2 * i + a[i];
    if (que.empty())
      devR[i] = 0;
    else {
      R[i][0] = que.front();
      devR[i] = devR[R[i][0]] + 1;
      for (int k = 1; (1 << k) <= devR[i]; k++) {
        R[i][k] = R[R[i][k - 1]][k - 1];
        vR[i][k] = min(vR[i][k - 1], vR[R[i][k - 1]][k - 1]);
      }
    }
    que.push_front(i);
  }
}
int separateL(int l, int r, int c) {
  if (a[r] <= c) return r;
  if (a[l] > c) return l - 1;
  int x = r;
  for (int K = 19; K >= 0; K--)
    if ((1 << K) <= devL[x] && a[L[x][K]] > c) x = L[x][K];
  return L[x][0];
}
void dealA(const AskNode &ask, int l, int r, int isNeedEnd) {
  int r1 = ask.r1, r2 = ask.r2, c1 = ask.c1, c2 = ask.c2;
  int pos2 = separateL(l, r, c2);
  if (l <= pos2) {
    check(ans[ask.id], (r2 - r1) + 2 * (r1 - pos2) + c2 - a[pos2] + isNeedEnd,
          s);
  }
  int K;
  if (pos2 == r) return;
  if (pos2 == l - 1)
    K = devL[r] - devL[l];
  else
    K = devL[r] - devL[pos2] - 1;
  int val = inf, x = r;
  for (int j = 0; K; K >>= 1, j++) {
    if (K & 1) {
      val = min(val, vL[x][j]);
      x = L[x][j];
    }
  }
  val = min(val, vL[x][0]);
  if (val != inf) {
    check(ans[ask.id], (r2 - r1) + 2 * r1 - c2 + val + isNeedEnd, s);
  }
}
void solveA(const AskNode &ask) {
  int pos = ask.r2;
  int r1 = ask.r1, r2 = ask.r2, c1 = ask.c1, c2 = ask.c2;
  for (int i = 19; i >= 0; i--)
    if ((1 << i) <= devL[pos] && L[pos][i] > ask.r1) pos = L[pos][i];
  if (devL[pos] == 0) return;
  pos = L[pos][0];
  int r = pos, l = getF(pos, devL[pos], L);
  pos = separateL(l, r, c1);
  if (l <= pos) {
    dealA(ask, l, pos, 0);
  }
  if (pos != r) {
    int x = l;
    if (l <= pos) {
      x = getF(r, devL[r] - devL[pos] - 1, L);
    }
    dealA(ask, x, r, 1);
  }
}
void solveB(const AskNode &ask) {
  int r1 = ask.r1, r2 = ask.r2, c1 = ask.c1, c2 = ask.c2;
  int x = r2;
  for (int K = 19; K >= 0; K--)
    if ((1 << K) <= devL[x] && L[x][K] >= r1) x = L[x][K];
  check(ans[ask.id], r2 - r1 + 1 + c2, s);
  check(ans[ask.id], r2 - r1 + abs(c2 - min(a[x], c1)), s);
  int l = x, r = r2;
  int pos = separateL(l, r, c2);
  if (l <= pos) {
    check(ans[ask.id], r2 - r1 + 1 + c2 - a[pos], s);
  }
  if (pos != r) {
    int x = l;
    if (l <= pos) {
      x = getF(r, devL[r] - devL[pos] - 1, L);
    }
    check(ans[ask.id], r2 - r1 + 1 + a[x] - c2, s);
  }
}
int separateR(int l, int r, int c) {
  if (a[l] <= c) return l;
  if (a[r] > c) return r + 1;
  int x = l;
  for (int K = 19; K >= 0; K--)
    if ((1 << K) <= devR[x] && a[R[x][K]] > c) x = R[x][K];
  return R[x][0];
}
void dealC(const AskNode &ask, int l, int r, int isNeedEnd) {
  int r1 = ask.r1, r2 = ask.r2, c1 = ask.c1, c2 = ask.c2;
  int pos2 = separateR(l, r, c2);
  if (pos2 <= r) {
    check(ans[ask.id], (r2 - r1) + 2 * (pos2 - r2) + c2 - a[pos2] + isNeedEnd,
          s);
  }
  int K;
  if (pos2 == l) return;
  if (pos2 == r + 1)
    K = devR[l] - devR[r];
  else
    K = devR[l] - devR[pos2] - 1;
  int val = inf, x = l;
  for (int j = 0; K; K >>= 1, j++) {
    if (K & 1) {
      val = min(val, vR[x][j]);
      x = R[x][j];
    }
  }
  val = min(val, vR[x][0]);
  if (val != inf) {
    check(ans[ask.id], (r2 - r1) - 2 * r2 - c2 + val + isNeedEnd, s);
  }
}
void solveC(const AskNode &ask) {
  int r1 = ask.r1, r2 = ask.r2, c1 = ask.c1, c2 = ask.c2;
  int x = r2;
  for (int K = 19; K >= 0; K--)
    if ((1 << K) <= devL[x] && L[x][K] >= r1) x = L[x][K];
  c1 = min(c1, a[x]);
  int l = r2, r = getF(r2, devR[r2], R);
  int pos = separateR(l, r, c1);
  if (pos <= r) dealC(ask, pos, r, 0);
  if (pos != l) {
    int x = r;
    if (pos <= r) x = getF(l, devR[l] - devR[pos] - 1, R);
    dealC(ask, l, x, 1);
  }
}
void solve(const vector<AskNode> &asks) {
  init();
  for (int i = 0; i < (asks.size()); i++) {
    solveA(asks[i]);
    solveB(asks[i]);
    solveC(asks[i]);
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < (n); i++) scanf("%d", &a[i]);
  scanf("%d", &q);
  for (int i = 0; i < (q); i++) {
    ans[i] = -1;
    AskNode tmp;
    tmp.read(i);
    if (tmp.r1 <= tmp.r2)
      asks[0].push_back(tmp);
    else {
      tmp.r1 = n - 1 - tmp.r1;
      tmp.r2 = n - 1 - tmp.r2;
      asks[1].push_back(tmp);
    }
  }
  solve(asks[0]);
  reverse(a, a + n);
  solve(asks[1]);
  for (int i = 0; i < (q); i++) printf("%d\n", ans[i]);
  return 0;
}
