#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  scanf("%d\n", &N);
  vector<long long> x(N);
  map<long long, int> xmap;
  for (int i = 0; i < N; ++i) {
    long long xi;
    scanf("%lld", &xi);
    getchar();
    x[i] = xi;
    xmap.emplace(xi, i);
  }
  long long L;
  scanf("%lld\n", &L);
  vector<int> left(N);
  vector<int> right(N);
  vector<map<int, int>> lmap(N);
  vector<map<int, int>> rmap(N);
  for (int i = 0; i < N; ++i) {
    auto it = xmap.lower_bound(x[i] - L);
    left[i] = ((it == xmap.end()) ? 0 : it->second);
    it = xmap.upper_bound(x[i] + L);
    right[i] = ((it == xmap.end()) ? N : it->second) - 1;
    lmap[i].emplace(left[i], 1);
    rmap[i].emplace(right[i], 1);
  }
  for (int i = 1; i < N; ++i) {
    for (int j = i + 1; j < N && left[j] <= i; ++j) {
      if (left[j] < i) continue;
      for (auto& elem : lmap[i]) {
        if (elem.first == i) continue;
        lmap[j].emplace(elem.first, elem.second + 1);
      }
    }
  }
  for (int i = N - 2; i >= 0; --i) {
    for (int j = i - 1; j >= 0 && i <= right[j]; --j) {
      if (i < right[j]) continue;
      for (auto& elem : rmap[i]) {
        if (elem.first == i) continue;
        rmap[j].emplace(elem.first, elem.second + 1);
      }
    }
  }
  int Q;
  scanf("%d\n", &Q);
  for (int q = 0; q < Q; ++q) {
    int a, b;
    scanf("%d %d\n", &a, &b);
    --a;
    --b;
    if (a < b) {
      printf("%d\n", rmap[a].lower_bound(b)->second);
    } else {
      printf("%d\n", lmap[a].upper_bound(b)->second + 1);
    }
  }
}
