#include <bits/stdc++.h>
std::vector<int> V[1000005 << 2];
int n, m, minn[1000005 << 2], a[1000005], ans[1000005], now;
int read() {
  char c = getchar();
  int ans = 0;
  bool flag = 1;
  while (c < '0' || c > '9') flag &= (c != '-'), c = getchar();
  while (c >= '0' && c <= '9') ans = ans * 10 + c - '0', c = getchar();
  return flag ? ans : -ans;
}
void Write(int x) {
  if (x < 10)
    putchar(x ^ 48);
  else
    Write(x / 10), putchar((x % 10) ^ 48);
  return;
}
struct node {
  int l, r, id;
  bool operator<(const node b) const { return r < b.r; }
} Q[1000005];
int min(int x, int y) { return x < y ? x : y; }
void build_tree(int L, int R, int rt) {
  for (register int i = L; i <= R; i++) V[rt].push_back(a[i]);
  std::sort(V[rt].begin(), V[rt].end()), minn[rt] = 1000000000;
  if (L == R) return;
  int mid = (L + R) >> 1;
  build_tree(L, mid, rt << 1), build_tree(mid + 1, R, rt << 1 | 1);
  return;
}
int query(int L, int R, int l, int r, int rt) {
  if (l <= L && R <= r) return minn[rt];
  int mid = (L + R) >> 1;
  if (mid < l) return query(mid + 1, R, l, r, rt << 1 | 1);
  if (mid >= r) return query(L, mid, l, r, rt << 1);
  return min(query(L, mid, l, r, rt << 1),
             query(mid + 1, R, l, r, rt << 1 | 1));
}
void modify(int L, int R, int l, int r, int rt, int x) {
  if (l <= L && R <= r) {
    std::vector<int>::iterator it =
        std::upper_bound(V[rt].begin(), V[rt].end(), x);
    if (it != V[rt].end()) minn[rt] = min(minn[rt], (*it) - x);
    if (it != V[rt].begin()) minn[rt] = min(minn[rt], x - *--it);
    if (now <= minn[rt]) return;
    if (L == R) {
      now = minn[rt];
      return;
    }
  }
  int mid = (L + R) >> 1;
  if (mid < r) modify(mid + 1, R, l, r, rt << 1 | 1, x);
  if (mid >= l) modify(L, mid, l, r, rt << 1, x);
  now = min(now, minn[rt] = min(minn[rt << 1], minn[rt << 1 | 1]));
  return;
}
int main() {
  n = read();
  for (register int i = 1; i <= n; i++) a[i] = read();
  m = read();
  for (register int i = 1; i <= m; i++)
    Q[i].l = read(), Q[i].r = read(), Q[i].id = i;
  std::sort(Q + 1, Q + 1 + m);
  build_tree(1, n, 1);
  int last = 1;
  for (register int i = 2; i <= n; i++) {
    now = 1000000000, modify(1, n, 1, i - 1, 1, a[i]);
    while (last <= m && Q[last].r == i)
      ans[Q[last].id] = query(1, n, Q[last].l, i, 1), ++last;
  }
  for (register int i = 1; i <= m; i++) Write(ans[i]), putchar('\n');
  return 0;
}
