#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
const int N = 1e5 + 5;
int n, l, q, x[N], root[N];
vector<int> artmatic[N];
bool vis[N];
int sq;
void dfs(int i, int r) {
  if (artmatic[r].size() >= sq && vis[i]) {
    artmatic[r].push_back(i);
    return;
  }
  if (!vis[i]) root[i] = r;
  vis[i] = 1;
  artmatic[r].push_back(i);
  if (i == n) return;
  int st = i, en = n;
  while (st < en) {
    int mid = (st + en + 1) / 2;
    if (x[i] + l < x[mid])
      en = mid - 1;
    else
      st = mid;
  }
  dfs(st, r);
}
int get(int i, int a) {
  int st = 0, en = artmatic[i].size() - 1;
  while (st < en) {
    int mid = (st + en) / 2;
    if (x[artmatic[i][mid]] >= x[a])
      en = mid;
    else
      st = mid + 1;
  }
  return st;
}
int ans(int i, int a, int b) {
  int idxa = get(i, a);
  int idxb = get(i, b);
  return idxb - idxa;
}
int main() {
  scanf("%d", &n);
  sq = sqrt(n);
  for (int i = 1; i <= n; ++i) scanf("%d", x + i);
  scanf("%d", &l);
  for (int i = 1; i <= n; ++i) {
    if (vis[i]) continue;
    dfs(i, i);
  }
  scanf("%d", &q);
  while (q--) {
    int a, b;
    scanf("%d%d", &a, &b);
    if (a == b) {
      puts("0");
      continue;
    }
    if (a > b) swap(a, b);
    int i = root[a];
    int idx = get(i, a), cur = 0;
    while (1) {
      if (artmatic[i].back() <= b) {
        cur += artmatic[i].back() - idx;
        i = root[artmatic[i].back()];
        idx = get(i, artmatic[i].back());
        continue;
      }
      cur += get(i, b) - idx;
      break;
    }
    printf("%d\n", cur);
  }
  return 0;
}
