#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define fre(x) freopen(x".in","r",stdin),freopen(x".out","w",stdout)
using namespace std;

inline int read(){
	int sum=0,f=1;char ch=getchar();
	while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){sum=sum*10+ch-'0';ch=getchar();}
	return f*sum;
}

const int N=100005;
struct node{int l,r,pre,nxt,to2,sp2,to1,sp1;}a[N];
struct ques{int l,r,id,ans;}q[N];
int n,m,L,p[N];
int bl[N],gap;

inline bool cmp(ques a,ques b){
	return a.l!=b.l? a.l<b.l:a.r<b.r;
}

inline bool cmp1(ques a,ques b){return a.id<b.id;}

inline int work2(int l,int r){
	int ans=0;
	while(bl[l]!=bl[r]) ans+=a[l].sp2,l=a[l].to2;
	while(l<r) ans++,l=a[l].nxt;
	return ans;
}

inline int work1(int l,int r){
	int ans=0;
	while(bl[l]!=bl[r]) ans+=a[l].sp1,l=a[l].to1;
	while(l>r) ans++,l=a[l].pre;
	return ans;
}

signed main(){
	n=read();gap=sqrt(n);
	for(int i=1;i<=n;i++) p[i]=read();
	for(int i=1;i<=n;i++) bl[i]=(i-1)/gap+1;
	L=read();m=read();
	for(int i=1;i<=m;i++) q[i].l=read(),q[i].r=read();
	for(int i=1;i<=m;i++) q[i].id=i;
	for(int i=1;i<=m;i++) if(q[i].l>q[i].r) swap(q[i].l,q[i].r);
	for(int i=1;i<=n;i++){
		int k=p[i]+L;
		k=upper_bound(p+1,p+n+1,k)-p-1;
		a[i].nxt=k;
		if(!a[k].l||i<a[k].l) a[k].l=i;
		a[k].r=max(a[k].r,i);
		a[i].pre=lower_bound(p+1,p+n+1,p[i]-L)-p;
	}
	for(int i=1;i<=n;i++){
		int p=i;
		while(bl[p]==bl[i]&&bl[p]!=bl[n]&&a[p].nxt!=p) p=a[p].nxt,a[i].sp2++;
		a[i].to2=p;
		p=i;
		while(bl[p]==bl[i]&&bl[p]!=bl[1]&&a[p].pre!=p) p=a[p].pre,a[i].sp1++;
		a[i].to1=p;
	}
	for(int i=1;i<=m;i++){
		if(q[i].l<q[i].r) q[i].ans=work2(q[i].l,q[i].r);
		else q[i].ans=work1(q[i].l,q[i].r);
	}
	for(int i=1;i<=m;i++) printf("%d\n",q[i].ans);
	return 0;
}
