#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;

#define MAXI 100000

//pbds
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
/*can use insert, find_by_order returns iterator, order_of_key*/
/*no repeated element*/

//input
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int hotels, maxdist, queries, temp;
    cin >> hotels;
    ordered_set loc;
    for(int one = 0; one < hotels; one++){
        cin >> temp;
        loc.insert(temp);
    }
    cin >> maxdist >> queries;
    int a[queries], b[queries];

    //precompute the closest hotels to left
    int l[hotels];
    l[0] = -1;
    for(int one = 0; one < hotels-1; one++){
        int temp = *loc.find_by_order(one+1);
        l[one+1] = loc.order_of_key(temp-maxdist);
    }

    //queries
    for(int one = 0; one < queries; one++){
        cin >> a[one] >> b[one];
        a[one]--; b[one]--;
        int cnt = 0;
        if(a[one] > b[one]){
            swap(a[one], b[one]);
        }
        //assume b[one] > a[one]
        while(b[one] > a[one]){
            temp = b[one];
            b[one] = l[temp];
            cnt++;
        }
        cout << cnt << endl;
    }
}