# include "cstdio"
# include "iostream"
# include "algorithm"
# define Maxn 100005
using namespace std;
inline int read()
{
	int ok=1,k=0;
	char c=getchar();
	while(c<'0'||c>'9')
	{
		if(c=='-')
		ok=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9')
	{
		k=k*10+c-'0';
		c=getchar();
	}
	return ok*k;
}
struct node{
	int x;
	int xh;
}sd[Maxn];
bool cmp(node a,node b)
{
	return a.x<b.x;
}
int f[Maxn],next[Maxn];
int main()
{
	int n,maxn;
	n=read();
	for(int i=1;i<=n;i++)
	{
		sd[i].xh=i;
	    f[i]=read();
		sd[i].x=f[i];
	}
	int ll;
	ll=read();
	sort(sd+1,sd+n+1,cmp);
	for(int i=1;i<=n;i++)
	{
		int tot=f[i]+ll;
		int l=1,r=n;
		while(l<=r)
		{
			int mid=(l+r)>>1;
			if(sd[mid].x>tot)
			r=mid-1;
			else
			l=mid+1; 
		}
		next[i]=sd[r].xh;
	}
	int m;
	m=read();
	for(int i=1;i<=m;i++)
	{
		int l,r,ans=0;
		l=read();
		r=read();
		if(f[l]>f[r])
		swap(l,r);
		while(f[l]<f[r])
		{
			ans++;
			l=next[l];
		}
		printf("%d\n",ans);
	}
	return 0;
}