from bisect import bisect_right,bisect_left
N=int(input())
x=[0]+list(map(int,input().split()))
L=int(input())
Q=int(input())
y=[None]*(N+1)
for _ in range(Q):
    a,b=sorted(map(int,input().split()))
    c=0
    p=[a]
    while a<b:
        if y[a]:
            i=bisect_left(y[a],a)
            j=bisect_left(y[a],b)
            c+=min(j,len(y[a])-1)-i
            a=y[a][-1]
            continue
        y[a]=p
        c+=1
        a=bisect_right(x,x[a]+L,a)-1
        p.append(a)
    print(c)