Artsem is on vacation and wants to buy souvenirs for his two teammates. There are n souvenir shops along the street. In i-th shop Artsem can buy one souvenir for ai dollars, and he cannot buy more than one souvenir in one shop. He doesn't want to introduce envy in his team, so he wants to buy two souvenirs with least possible difference in price.

Artsem has visited the shopping street m times. For some strange reason on the i-th day only shops with numbers from li to ri were operating (weird? yes it is, but have you ever tried to come up with a reasonable legend for a range query problem?). For each visit, Artsem wants to know the minimum possible difference in prices of two different souvenirs he can buy in the opened shops.

In other words, for each Artsem's visit you should find the minimum possible value of |as - at| where li ≤ s, t ≤ ri, s ≠ t.

Input

The first line contains an integer n (2 ≤ n ≤ 105).

The second line contains n space-separated integers a1, ..., an (0 ≤ ai ≤ 109).

The third line contains the number of queries m (1 ≤ m ≤ 3·105).

Next m lines describe the queries. i-th of these lines contains two space-separated integers li and ri denoting the range of shops working on i-th day (1 ≤ li < ri ≤ n).

Output

Print the answer to each query in a separate line.

Example

Input

8
3 1 4 1 5 9 2 6
4
1 8
1 3
4 8
5 7


Output

0
1
1
3
#include <bits/stdc++.h>
using namespace std;
const int INF = 1791791791;
const long long INFLL = 1791791791791791791ll;
template <int input_buf_size, int output_buf_size>
class FastIO {
  char cbuf[input_buf_size + 1];
  int icur = 0;
  inline bool go_to_next_token() {
    while (cbuf[icur] == ' ' || cbuf[icur] == '\n') icur++;
    while (cbuf[icur] == 0) {
      icur = 0;
      if (fgets(cbuf, sizeof(cbuf), stdin) != cbuf) return false;
      while (cbuf[icur] == ' ' || cbuf[icur] == '\n') icur++;
    }
    return true;
  }

 public:
  string readString() {
    assert(go_to_next_token());
    string ans;
    while (cbuf[icur] != ' ' && cbuf[icur] != '\n' && cbuf[icur] != 0)
      ans.push_back(cbuf[icur++]);
    ans.shrink_to_fit();
    return ans;
  }
  template <class int_type>
  int_type readInt() {
    assert(go_to_next_token());
    int_type x = 0;
    bool m = cbuf[icur] == '-';
    if (m) icur++;
    while ('0' <= cbuf[icur] && cbuf[icur] <= '9') {
      x *= 10;
      x += (cbuf[icur] - '0');
      icur++;
    }
    if (m) x = -x;
    return x;
  }
  bool seekEof() { return !go_to_next_token(); }

 private:
  char obuf[output_buf_size + 1];
  int ocur = 0;
  inline void write_string(const char* str, size_t sz = 0) {
    if (sz == 0) sz = strlen(str);
    if (ocur + sz > output_buf_size) {
      fputs(obuf, stdout);
      fputs(str, stdout);
      ocur = 0;
      obuf[0] = 0;
      return;
    }
    strcpy(obuf + ocur, str);
    ocur += sz;
    obuf[ocur] = 0;
  }

 public:
  template <class int_type>
  void writeInt(int_type x, bool sp = true) {
    char buf[20];
    int c = 0;
    if (x < 0) {
      buf[c++] = '-';
      x = -x;
    }
    int s = c;
    if (x == 0) {
      buf[c++] = '0';
    }
    while (x > 0) {
      buf[c++] = (x % 10) + '0';
      x /= 10;
    }
    for (int i = 0; 2 * i < c - s; i++) {
      swap(buf[s + i], buf[c - 1 - i]);
    }
    buf[c] = 0;
    write_string(buf, c);
    if (sp) write_string(" ", 1);
  }
  void writeString(string s, bool space = true) {
    write_string(s.c_str(), s.size());
    if (space) write_string(" ", 1);
  }
  void writeEndl() { write_string("\n", 1); }
  void flush() {
    fputs(obuf, stdout);
    ocur = 0;
    obuf[0] = 0;
  }

 private:
  bool lflush;

 public:
  FastIO(bool local_flush) {
    obuf[0] = 0;
    lflush = local_flush;
  }
  ~FastIO() { fputs(obuf, stdout); }
};
FastIO<10000000, 10000000> IO(true);
class segment_tree {
  int n;
  vector<int> t, mod;
  void push(int v) {
    mod[2 * v + 1] = min(mod[2 * v + 1], mod[v]);
    mod[2 * v + 2] = min(mod[2 * v + 2], mod[v]);
    t[v] = min(min(t[2 * v + 1], mod[2 * v + 1]),
               min(t[2 * v + 2], mod[2 * v + 2]));
    mod[v] = INF;
  }
  void update_segment(int v, int L, int R, int l, int r, int val) {
    if (R <= l || r <= L)
      return;
    else if (l <= L && R <= r)
      mod[v] = min(mod[v], val);
    else {
      push(v);
      update_segment(2 * v + 1, L, (L + R) >> 1, l, r, val);
      update_segment(2 * v + 2, (L + R) >> 1, R, l, r, val);
      t[v] = min(min(t[2 * v + 1], mod[2 * v + 1]),
                 min(t[2 * v + 2], mod[2 * v + 2]));
    }
  }
  int min_on_segment(int v, int L, int R, int l, int r) {
    if (R <= l || r <= L)
      return INF;
    else if (l <= L && R <= r)
      return min(t[v], mod[v]);
    else {
      push(v);
      return min(min_on_segment(2 * v + 1, L, (L + R) >> 1, l, r),
                 min_on_segment(2 * v + 2, (L + R) >> 1, R, l, r));
    }
  }

 public:
  segment_tree(int _n) {
    n = _n;
    t.resize(4 * n, INF);
    mod.resize(4 * n, INF);
  }
  void update_segment(int l, int r, int val) {
    update_segment(0, 0, n, l, r, val);
  }
  int min_on_segment(int l, int r) { return min_on_segment(0, 0, n, l, r); }
};
class pair_set {
  int n;
  vector<int> a;
  struct Node {
    int t;
    Node *L, *R;
    Node() {
      L = R = nullptr;
      t = -INF;
    }
    Node(Node* nd) {
      L = nd->L;
      R = nd->R;
      t = nd->t;
    }
  };
  void build(Node*& v, int L, int R) {
    v = new Node();
    if (L == R - 1) return;
    build(v->L, L, (L + R) >> 1);
    build(v->R, (L + R) >> 1, R);
  }
  void set_val(Node*& v, int L, int R, int i, int val) {
    if (R <= i || i < L) return;
    v = new Node(v);
    if (L == R - 1)
      v->t = max(v->t, val);
    else {
      set_val(v->L, L, (L + R) >> 1, i, val);
      set_val(v->R, (L + R) >> 1, R, i, val);
      v->t = max(v->L->t, v->R->t);
    }
  }
  int get_max(Node* v, int L, int R, int l, int r) {
    if (R <= l || r <= L)
      return -INF;
    else if (l <= L && R <= r)
      return v->t;
    else
      return max(get_max(v->L, L, (L + R) >> 1, l, r),
                 get_max(v->R, (L + R) >> 1, R, l, r));
  }
  int index(int x) {
    return distance(a.begin(), lower_bound((a).begin(), (a).end(), x));
  }

 public:
  typedef Node* state;
  state root;
  pair_set(const vector<int>& _a) {
    a = _a;
    sort((a).begin(), (a).end());
    a.resize(distance(a.begin(), unique((a).begin(), (a).end())));
    n = a.size();
    build(root, 0, n);
  }
  void add_pair(int ind, int val) {
    val = index(val);
    set_val(root, 0, n, val, ind);
  }
  int get_right_more(state st, int val) {
    val = index(val);
    return get_max(st, 0, n, val, n);
  }
  int get_right_seg(state st, int lt, int rt) {
    lt = index(lt);
    rt = index(rt);
    return get_max(st, 0, n, lt, rt);
  }
};
struct query {
  int l, r;
  int ans;
  query() { ans = INF; }
  query(int _l, int _r) {
    l = _l;
    r = _r;
    ans = INF;
  }
  void update(int new_ans) { ans = min(ans, new_ans); }
};
typedef query* qptr;
void solve(vector<int>& a, vector<query*> qs) {
  sort((qs).begin(), (qs).end(),
       [](const qptr& u, const qptr& b) -> bool { return u->r < b->r; });
  int n = a.size();
  pair_set ps(a);
  vector<pair_set::state> states(n + 1);
  states[0] = ps.root;
  for (int i = 0; i < ((int)(n)); ++i) {
    ps.add_pair(i, a[i]);
    states[i + 1] = ps.root;
  }
  int j = 0;
  segment_tree cans(n);
  for (int i = 0; i < ((int)(n)); ++i) {
    int rt = ps.get_right_more(states[i], a[i]);
    while (rt >= 0) {
      cans.update_segment(0, rt + 1, a[rt] - a[i]);
      int ort = rt;
      rt = ps.get_right_seg(states[rt], a[i], (a[i] + a[rt]) / 2 + 1);
      if (rt >= 0 && a[ort] - a[rt] <= a[rt] - a[i]) break;
    }
    while (j < (int)qs.size() && qs[j]->r == i) {
      qs[j]->update(cans.min_on_segment(qs[j]->l, qs[j]->r));
      j++;
    }
  }
}
int main() {
  int n = IO.readInt<int>();
  vector<int> a(n);
  for (int i = 0; i < ((int)(n)); ++i) a[i] = IO.readInt<int>();
  int m = IO.readInt<int>();
  vector<query> qs(m);
  for (int i = 0; i < ((int)(m)); ++i) {
    qs[i].l = IO.readInt<int>() - 1;
    qs[i].r = IO.readInt<int>() - 1;
  }
  vector<query*> qp(m);
  for (int i = 0; i < ((int)(m)); ++i) qp[i] = &qs[i];
  solve(a, qp);
  for (int i = 0; i < ((int)(m)); ++i) {
    qs[i].l = n - qs[i].l - 1;
    qs[i].r = n - qs[i].r - 1;
    swap(qs[i].l, qs[i].r);
  }
  reverse((a).begin(), (a).end());
  solve(a, qp);
  for (int i = 0; i < ((int)(m)); ++i) {
    IO.writeInt(qs[i].ans);
    IO.writeEndl();
  }
  return 0;
}
