#include <bits/stdc++.h>
using namespace std;
char buf[1 << 17];
int sl, sr;
char gc() {
  return sl == sr && (sr = (sl = 0) + fread(buf, 1, 1 << 17, stdin), sl == sr)
             ? EOF
             : buf[sl++];
}
int read() {
  int ans = 0, k = 1;
  char c = gc();
  while (!isdigit(c)) {
    if (c == '-') k = -1;
    c = gc();
  }
  while (isdigit(c)) {
    ans = ans * 10 + c - '0';
    c = gc();
  }
  return k * ans;
}
struct node {
  int x;
  int xh;
} sd[100005];
struct node1 {
  int l;
  int r;
  int ans;
  int xh;
} q[100005];
bool cmp(node a, node b) { return a.x < b.x; }
int f[100005], fuck[100005];
bool cmp1(node1 a, node1 b) {
  if (a.l == b.l) return f[a.r] < f[b.r];
  return a.l < b.l;
}
bool cmp2(node1 a, node1 b) { return a.xh < b.xh; }
int main() {
  int n, maxn;
  n = read();
  for (int i = 1; i <= n; i++) {
    sd[i].xh = i;
    f[i] = read();
    sd[i].x = f[i];
  }
  int ll;
  ll = read();
  sort(sd + 1, sd + n + 1, cmp);
  for (int i = 1; i <= n; i++) {
    int tot = f[i] + ll;
    int l = 1, r = n;
    while (l <= r) {
      int mid = (l + r) >> 1;
      if (sd[mid].x > tot)
        r = mid - 1;
      else
        l = mid + 1;
    }
    fuck[i] = sd[r].xh;
  }
  int m;
  m = read();
  for (int i = 1; i <= m; i++) {
    q[i].xh = i;
    int l, r;
    l = read();
    r = read();
    if (f[l] > f[r]) swap(l, r);
    q[i].l = l;
    q[i].r = r;
  }
  sort(q + 1, q + m + 1, cmp1);
  int now = 1, l = 1, r;
  int ans = 0;
  for (int i = 1; i <= m; i++) {
    r = q[i].r;
    if (now != q[i].l) {
      l = q[i].l;
      ans = 0;
    }
    now = q[i].l;
    while (f[l] < f[r]) {
      ans++;
      l = fuck[l];
    }
    q[i].ans = ans;
  }
  sort(q + 1, q + m + 1, cmp2);
  for (int i = 1; i <= m; i++) printf("%d\n", q[i].ans);
  return 0;
}
