#include <bits/stdc++.h>
using namespace std;
long long int const MOD = 1000000007;
long long int const INF = (long long int)1 << 61;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long int n;
  cin >> n;
  vector<long long int> x(n);
  for (int i = 0; i < n; i++) {
    cin >> x[i];
  }
  long long int L;
  cin >> L;
  long long int q;
  cin >> q;
  vector<long long int> a(q), b(q);
  for (int i = 0; i < q; i++) {
    cin >> a[i] >> b[i];
    if (a[i] > b[i]) {
      swap(a[i], b[i]);
    }
    a[i]--;
    b[i]--;
  }
  vector<long long int> dp(n, 0);
  vector<long long int> next(n, 0);
  vector<long long int> down(n, 0);
  for (int i = 0; i < n; i++) {
    auto itr = upper_bound(x.begin(), x.end(), x[i] + L);
    long long int idx = (long long int)(itr - x.begin()) - 1;
    next[i] = idx;
    auto itr2 = lower_bound(x.begin(), x.end(), x[i] - L);
    long long int idx2 = (long long int)(itr2 - x.begin());
    down[i] = idx2;
  }
  for (int i = 1; i < n; i++) {
    dp[i] = dp[down[i]] + (i - down[i] - 1);
  }
  for (int i = 0; i < q; i++) {
    cout << (b[i] - a[i]) - ((next[a[i]] < b[i] ? dp[b[i]] - dp[next[a[i]]] +
                                                      (next[a[i]] - a[i] - 1)
                                                : b[i] - a[i] - 1))
         << endl;
  }
  return 0;
}
