#include <bits/stdc++.h>
using namespace std;
struct data {
  int first, second, id;
  data(int _f, int _s, int _id) : first(_f), second(_s), id(_id) {}
};
const int N = (int)1e5 + 5;
int n, m, len, a[N], b[N], dp[N], cnt[N], res[N], sz;
vector<data> q;
void add(int x, int &tmp) {
  ++cnt[x];
  if (cnt[x] == 1) ++tmp;
}
void _remove(int x, int &tmp) {
  --cnt[x];
  if (cnt[x] == 0) --tmp;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d", a + i);
  scanf("%d%d", &len, &m);
  for (int i = n, j = n; i >= 1; --i) {
    while (j >= 1 && a[j] - a[i] > len) --j;
    b[i] = j;
    if (i != j) dp[i] = dp[j] + 1;
  }
  for (int i = 1, u, v; i <= m; ++i) {
    scanf("%d%d", &u, &v);
    if (u > v) swap(u, v);
    q.push_back(data(u, v - 1, i));
  }
  sz = sqrt(n);
  sort(q.begin(), q.end(), [](data x, data y) {
    return (x.first / sz < y.first / sz) ||
           (x.first / sz == y.first / sz && x.second < y.second);
  });
  int tmp = 0;
  for (int i = q[0].first; i <= q[0].second; ++i) add(dp[i], tmp);
  res[q[0].id] = tmp;
  for (int i = 1; i < m; ++i) {
    int lo = q[i - 1].first, hi = q[i - 1].second;
    while (lo > q[i].first) add(dp[lo - 1], tmp), --lo;
    while (lo < q[i].first) _remove(dp[lo], tmp), ++lo;
    while (hi > q[i].second) _remove(dp[hi], tmp), --hi;
    while (hi < q[i].second) add(dp[hi + 1], tmp), ++hi;
    res[q[i].id] = tmp;
  }
  for (int i = 1; i <= m; ++i) printf("%d\n", res[i]);
  return 0;
}
