#include <bits/stdc++.h>
int n;
int limit;
int xs[112345];
int dp[2048];
int as[112345];
int bs[112345];
void init() {
  for (int i = 0; i < 2048; ++i) {
    dp[i] = (1 << 29);
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) scanf("%d", &xs[i]);
  scanf("%d", &limit);
  int qq;
  scanf("%d", &qq);
  for (int i = 0; i < qq; ++i) {
    scanf("%d %d", &as[i], &bs[i]);
  }
  if (not(n <= 1000 and qq <= 1000)) {
    return 0;
  }
  for (int i = 0; i < qq; ++i) {
    init();
    int a = as[i], b = bs[i];
    if (a > b) std::swap(a, b);
    a -= 1;
    b -= 1;
    std::queue<int> q;
    q.push(a);
    dp[a] = 0;
    while (not q.empty()) {
      int t = q.front();
      q.pop();
      for (int k = t + 1; k < n; ++k) {
        if (xs[t] + limit < xs[k]) break;
        if (dp[k] < dp[t] + 1) continue;
        dp[k] = dp[t] + 1;
        q.push(k);
      }
    }
    printf("%d\n", dp[b]);
  }
  return 0;
}
