#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
long long n, m, a[200005], mi, ans[400005];
struct node {
  long long minn;
} tree[400005];
struct Node {
  long long l, r, id;
  bool operator<(const Node &a) const { return r < a.r; }
} q[400005];
long long read() {
  long long f = 0, w = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') w = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    f = f * 10 + ch - '0';
    ch = getchar();
  }
  return f * w;
}
vector<long long> v[400005];
void build(long long tr, long long l, long long r) {
  for (long long i = l; i <= r; i++) v[tr].push_back(a[i]);
  sort(v[tr].begin(), v[tr].end());
  tree[tr].minn = inf;
  if (l == r) return;
  long long mid = (l + r) / 2;
  build(tr * 2, l, mid), build(tr * 2 + 1, mid + 1, r);
}
void update(long long tr, long long stdl, long long stdr, long long pos,
            long long k) {
  if (stdr <= pos) {
    vector<long long>::iterator it = upper_bound(v[tr].begin(), v[tr].end(), k);
    if (it != v[tr].end()) tree[tr].minn = min(tree[tr].minn, *it - k);
    if (it != v[tr].begin()) tree[tr].minn = min(tree[tr].minn, k - *(it - 1));
    if (mi <= tree[tr].minn) return;
    if (stdl == stdr) {
      mi = min(mi, tree[tr].minn);
      return;
    }
  }
  long long mid = (stdl + stdr) / 2;
  if (pos > mid) update(tr * 2 + 1, mid + 1, stdr, pos, k);
  update(tr * 2, stdl, mid, pos, k);
  tree[tr].minn =
      min(tree[tr].minn, min(tree[tr * 2].minn, tree[tr * 2 + 1].minn));
  mi = min(mi, tree[tr].minn);
}
long long query(long long tr, long long stdl, long long stdr, long long l,
                long long r) {
  if (l > stdr || r < stdl) return inf;
  if (l <= stdl && r >= stdr) return tree[tr].minn;
  long long mid = (stdl + stdr) / 2;
  return min(query(tr * 2, stdl, mid, l, r),
             query(tr * 2 + 1, mid + 1, stdr, l, r));
}
signed main() {
  n = read();
  for (long long i = 1; i <= n; i++) a[i] = read();
  build(1, 1, n);
  m = read();
  for (long long i = 1; i <= m; i++) {
    q[i].l = read(), q[i].r = read();
    q[i].id = i;
  }
  sort(q + 1, q + 1 + m);
  for (long long pos = 1, i = 2; i <= n; i++) {
    mi = inf;
    update(1, 1, n, i - 1, a[i]);
    for (; pos <= m && q[pos].r <= i; pos++) {
      ans[q[pos].id] = query(1, 1, n, q[pos].l, i);
    }
  }
  for (long long i = 1; i <= m; i++) printf("%lld\n", ans[i]);
  return 0;
}
