#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e5 + 10;
const long long MOD = 1e9 + 7;
int N, M, K, L, Q;
int A[MAX];
int jump[MAX][33];
vector<int> vec;
int func(int i, int j) {
  if (j == 0) return jump[i][0];
  int &ret = jump[i][j];
  if (ret != -1) return ret;
  return ret = func(func(i, j - 1), j - 1);
}
int main() {
  int i, j, k;
  scanf("%d", &N);
  for (i = 1; i <= N; ++i) {
    scanf("%d", &A[i]);
    vec.push_back(A[i]);
  }
  scanf("%d%d", &L, &Q);
  sort(vec.begin(), vec.end());
  memset(jump, -1, sizeof(jump));
  for (i = 1; i <= N; ++i) {
    auto it = upper_bound(vec.begin(), vec.end(), A[i] + L);
    --it;
    jump[i][0] = it - vec.begin() + 1;
  }
  j = 0;
  while (N > (1 << j)) j++;
  for (i = 1; i <= N; ++i) {
    func(i, j);
  }
  for (i = 1; i <= N; ++i) {
    for (k = 0; k <= j; ++k) {
      printf("%d ", jump[i][k]);
    }
    printf("\n");
  }
  int a, b;
  for (i = 1; i <= Q; ++i) {
    scanf("%d%d", &a, &b);
    int days = 0;
    if (b < a) swap(a, b);
    for (k = j; k >= 0; --k) {
      if (jump[a][k] < b) {
        days += (1 << k);
        a = jump[a][k];
      }
    }
    printf("%d\n", days + 1);
  }
}
