#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template <class T>
inline T gcd(T a, T b) {
  while (b) {
    a %= b;
    swap(a, b);
  }
  return a;
}
template <class T>
inline T lcm(T a, T b) {
  return a * b / gcd(a, b);
}
const long long MAXN = 2e6 + 7, K = 200043, M = 2500, INF = 1e18 + 7, LOG = 20;
const long double PI = acos(-1.0);
long long MOD = 1e9 + 7;
template <class T>
T sqr(T a) {
  return a * a;
}
long long mul(long long a, long long b) {
  return ((a % MOD) * (b % MOD)) % MOD;
}
long long sum(long long a, long long b) {
  return ((a % MOD) + (b % MOD)) % MOD;
}
long long sub(long long a, long long b) { return sum(a, MOD - b); }
long long bin_pow(long long a, long long n) {
  long long res = 1;
  while (n > 0) {
    if (n & 1) res = mul(res, a);
    a = mul(a, a);
    n >>= 1;
  }
  return res;
}
long long inv(long long x) { return bin_pow(x, MOD - 2) % MOD; }
long long dp[MAXN][20];
map<int, int> m;
set<int> s;
int n, l, q;
int x[MAXN];
void solve() {
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> x[i];
    m[x[i]] = i;
    s.insert(x[i]);
  }
  s.insert(2e9);
  cin >> l;
  for (int i = 1; i <= n; ++i) {
    dp[i][0] = m[*--s.upper_bound(x[i] + l)];
  }
  for (int j = 1; j <= LOG; ++j) {
    for (int i = 1; i <= n; ++i) {
      dp[i][j] = dp[dp[i][j - 1]][j - 1];
    }
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 0; j < LOG; ++j) {
      cout << dp[i][j] << ' ';
    }
    cout << '\n';
    ;
  }
  cin >> q;
  while (q-- > 0) {
    long long L, R;
    cin >> L >> R;
    if (L > R) swap(L, R);
    int ans = 0;
    for (int k = LOG; k >= 0; --k) {
      if (dp[L][k] + 1 >= R) continue;
      ans += (1 << k);
      L = dp[L][k];
    }
    cout << ans + 1 << '\n';
    ;
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t-- > 0) solve();
  return 0;
}
