#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, sq = sqrt(N);
int n, l, q, x[N], a, b, to[N];
vector<pair<int, int>> all;
vector<pair<int, int>> ans[N];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", x + i);
    all.push_back({x[i], i});
  }
  scanf("%d", &l);
  sort(all.begin(), all.end());
  for (int i = 0; i < all.size(); ++i) to[all[i].second] = i;
  for (int i = 0; i < all.size(); ++i) {
    int k = min((int)all.size() - 1, i + sq);
    int cur = i;
    int t = 0;
    while (cur != k) {
      int st = cur, en = k;
      while (st < en) {
        int mid = (st + en + 1) / 2;
        if (all[cur].first + l < all[mid].first)
          en = mid - 1;
        else
          st = mid;
      }
      ++t;
      for (int j = cur + 1; j <= st; ++j) ans[i].push_back({j, t});
      cur = st;
    }
  }
  scanf("%d", &q);
  while (q--) {
    scanf("%d%d", &a, &b);
    int aa = to[a];
    int bb = to[b];
    if (aa > bb) swap(aa, bb);
    long long anss = 0;
    while (ans[aa].back().first <= bb) {
      anss += ans[aa].back().second;
      aa = ans[aa].back().first;
    }
    if (aa != bb) anss += ans[aa][bb - aa - 1].second;
    printf("%lld\n", anss);
  }
  return 0;
}
