#include <bits/stdc++.h>
using namespace std;
const int maxn = 100000 + 10, maxm = 300000 + 10, inf = 2000000000;
struct dong {
  int l, r, id;
} ask[maxm];
int tree[maxn * 4], ans[maxm], a[maxn], sta[80];
set<int> e[maxn * 4];
int i, j, k, l, r, t, n, m, mi, top;
int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
bool cmp(dong a, dong b) { return a.r < b.r; }
void build(int p, int l, int r) {
  tree[p] = inf;
  if (l == r) return;
  int mid = (l + r) / 2;
  build(p * 2, l, mid);
  build(p * 2 + 1, mid + 1, r);
}
void change(int p, int l, int r, int qr, int d) {
  if (l == r) {
    if (l == qr) return;
    tree[p] = min(tree[p], abs(d - a[l]));
    mi = min(mi, tree[p]);
    return;
  }
  if (r <= qr) {
    set<int>::iterator it = e[p].lower_bound(d);
    if ((it == e[p].end() || abs(*it - d) >= mi) &&
        (it == e[p].begin() || abs(*(--it) - d) >= mi)) {
      mi = min(mi, tree[p]);
      return;
    }
    int mid = (l + r) / 2;
    change(p * 2 + 1, mid + 1, r, qr, d);
    change(p * 2, l, mid, qr, d);
    tree[p] = min(tree[p * 2], tree[p * 2 + 1]);
    return;
  }
  int mid = (l + r) / 2;
  if (qr <= mid)
    change(p * 2, l, mid, qr, d);
  else {
    change(p * 2 + 1, mid + 1, r, qr, d);
    change(p * 2, l, mid, qr, d);
  }
  tree[p] = min(tree[p * 2], tree[p * 2 + 1]);
}
void cr(int p, int l, int r, int a, int b) {
  e[p].insert(b);
  if (l == r) return;
  int mid = (l + r) / 2;
  if (a <= mid)
    cr(p * 2, l, mid, a, b);
  else
    cr(p * 2 + 1, mid + 1, r, a, b);
}
int query(int p, int l, int r, int a, int b) {
  if (l == a && r == b) return tree[p];
  int mid = (l + r) / 2;
  if (b <= mid)
    return query(p * 2, l, mid, a, b);
  else if (a > mid)
    return query(p * 2 + 1, mid + 1, r, a, b);
  else
    return min(query(p * 2, l, mid, a, mid),
               query(p * 2 + 1, mid + 1, r, mid + 1, b));
}
void write(int x) {
  if (!x) {
    putchar('0');
    putchar('\n');
    return;
  }
  top = 0;
  while (x) {
    sta[++top] = x % 10;
    x /= 10;
  }
  while (top) {
    putchar('0' + sta[top]);
    top--;
  }
  putchar('\n');
}
int main() {
  n = read();
  for (i = 1; i <= n; i++) a[i] = read();
  build(1, 1, n);
  m = read();
  for (i = 1; i <= m; i++) ask[i].l = read(), ask[i].r = read(), ask[i].id = i;
  sort(ask + 1, ask + m + 1, cmp);
  r = 0;
  for (i = 1; i <= m; i++) {
    while (r < ask[i].r) {
      r++;
      mi = inf;
      change(1, 1, n, r, a[r]);
      cr(1, 1, n, r, a[r]);
    }
    ans[ask[i].id] = query(1, 1, n, ask[i].l, r);
  }
  for (i = 1; i <= m; i++) write(ans[i]);
}
