#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int sum = 0, f = 1;
  char ch = getchar();
  while (ch > '9' || ch < '0') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    sum = sum * 10 + ch - '0';
    ch = getchar();
  }
  return f * sum;
}
const int N = 100005;
struct node {
  int pre, nxt, to2, sp2;
} a[N];
struct ques {
  int l, r, id, ans;
} q[N];
int n, m, L, p[N];
int bl[N], gap, an[N];
inline bool cmp(ques a, ques b) { return a.l != b.l ? a.l < b.l : a.r < b.r; }
signed main() {
  n = read();
  gap = sqrt(n);
  for (int i = 1; i <= n; i++) p[i] = read();
  for (int i = 1; i <= n; i++) bl[i] = (i - 1) / gap + 1;
  L = read();
  m = read();
  for (int i = 1; i <= m; i++) q[i].l = read(), q[i].r = read();
  for (int i = 1; i <= m; i++) q[i].id = i;
  for (int i = 1; i <= m; i++)
    if (q[i].l > q[i].r) swap(q[i].l, q[i].r);
  for (int i = 1; i <= n; i++) {
    int k = p[i] + L;
    k = upper_bound(p + 1, p + n + 1, k) - p - 1;
    a[i].nxt = k;
  }
  for (int i = 1; i <= n; i++) {
    a[i].to2 = i;
    while (bl[a[i].to2] == bl[i] && bl[a[i].to2] != bl[n])
      a[i].to2 = a[a[i].to2].nxt, a[i].sp2++;
  }
  sort(q + 1, q + n + 1, cmp);
  for (int pl = 1, pr = 1; pl <= m; pl = pr = pr + 1) {
    while (q[pr].l == q[pr + 1].l) pr++;
    int l = q[pl].l, ans = 0;
    while (pl <= pr) {
      int r = q[pl].r;
      while (bl[l] != bl[r]) ans += a[l].sp2, l = a[l].to2;
      while (l < r) ans++, l = a[l].nxt;
      an[q[pl].id] = ans;
      pl++;
    }
  }
  for (int i = 1; i <= m; i++) printf("%d\n", an[i]);
  return 0;
}
