#include<cstdio>
#include<algorithm>
#include"lib/graph.hpp"
int x[1001]={};
int main(){
    int n,l,q;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)scanf("%d",&x[i]);
    scanf("%d%d",&l,&q);
    if(n>1000||q>1000){
        printf("0\n");
        return 0;
    }
    Graph g(n+1);
    for(int i=1;i<=n;i++){
        for(int j=i+1;j<=n;j++){
            if(std::abs(x[i]-x[j])<=l){
                g.addEdge(i,j);
            }
        }
    }
    for(int i=0;i<q;i++){
        int a,b;
        scanf("%d%d",&a,&b);
        weight minl[1001];
        g.dijkstra(minl,a);
        printf("%lld\n",minl[b]);
    }
    return 0;
}