#include <bits/stdc++.h>
const int maxn = 1e5 + 10;
using namespace std;
long long gcd(long long p, long long q) { return q == 0 ? p : gcd(q, p % q); }
long long qpow(long long p, long long q) {
  long long f = 1;
  while (q) {
    if (q & 1) f = f * p;
    p = p * p;
    q >>= 1;
  }
  return f;
}
int n, m, k, t, l[maxn], r[maxn], ans[maxn];
long long a[maxn], p;
vector<int> go[maxn], to[maxn], all;
void init() {
  for (int i = 0; i <= n - 1; i++) {
    r[i] = lower_bound(a, a + n, a[i] + p) - a;
    if (r[i] == n || a[r[i]] > a[i] + p) r[i]--;
    l[i] = lower_bound(a, a + n, a[i] - p) - a;
  }
}
int main() {
  int i, j;
  scanf("%d", &n);
  for (i = 0; i <= n - 1; i++) scanf("%lld", &a[i]);
  scanf("%lld", &p);
  init();
  int q;
  scanf("%d", &q);
  for (i = 0; i <= q - 1; i++) {
    int c, d;
    scanf("%d%d", &c, &d);
    c--, d--;
    all.push_back(d);
    if (c < d) go[c].push_back(i);
    if (c > d) to[c].push_back(i);
  }
  for (i = 0; i <= n - 1; i++) {
    for (int x : go[i]) {
      ans[x]++;
      if (r[i] < all[x]) go[r[i]].push_back(x);
    }
    go[i].clear();
  }
  for (i = n - 1; i >= 0; i--) {
    for (int x : to[i]) {
      ans[x]++;
      if (l[i] > all[x]) to[l[i]].push_back(x);
    }
    to[i].clear();
  }
  for (i = 0; i <= q - 1; i++) printf("%d\n", ans[i]);
  return 0;
}
