#include <bits/stdc++.h>
using namespace std;
const int noway = 98765432;
int N, L, Q;
int hotel[100005];
int garbage[400][400];
int main() {
  scanf("%d", &N);
  for (int n = 1; n <= N; n++) scanf("%d", &hotel[n]);
  scanf("%d%d", &L, &Q);
  if (N < 400) {
    int i, j, k, aj, bj, dis;
    for (i = 1; i <= N; i++)
      for (j = 1; j <= N; j++) {
        dis = hotel[j] > hotel[i] ? hotel[j] - hotel[i] : hotel[i] - hotel[j];
        if (dis <= L)
          garbage[i][j] = garbage[j][i] = 1;
        else
          garbage[i][j] = garbage[j][i] = noway;
      }
    for (i = 1; i <= N; i++)
      for (j = 1; j <= N; j++)
        for (k = 1; k <= N; k++)
          if (garbage[j][i] + garbage[i][k] < garbage[j][k])
            garbage[j][k] = garbage[j][i] + garbage[i][k];
    for (int j = 1; j <= Q; j++) {
      scanf("%d%d", &aj, &bj);
      printf("%d\n", garbage[aj][bj]);
    }
  }
  return 0;
}
