import bisect

n = int(input())
hotel_list = [ int(v) for v in input().split() ]
l = int(input())
ln = 16
hotel_list_2 = [ [ -1 for i in range(n) ]  for i in range(ln) ]

hotel_list_2[0] = [ bisect.bisect_right(hotel_list,v+l)-1  for v in hotel_list ]
for i in range(ln-1):
    hotel_list_2[i+1] = [ hotel_list_2[i][hotel_list_2[i][j]] for j in range(n) ]

def checkin(s,t):
    p, q = s, 0
    c = 1
    for i in range(ln):
        q = p
        p = hotel_list_2[i][s]
        if p == t:
            return c
        elif i == 0 and p > t:
            return c
        elif p > t:
            return c//2 + checkin(q,t)
        c *= 2

q = int(input())
for i in range(q):
    a, b = [ int(v)-1 for v in input().split() ]
    if a > b:
        a, b = b, a 
    print(checkin(a,b))
