import sys

input = sys.stdin.readline

import numpy as np



N = int(eval(input()))

X = np.array(input().split(), dtype = np.int64)

L = int(eval(input()))



U = N.bit_length()

# 各ホテルから、2^n回でどこまで行けるか

next_x = []

next_x.append((np.searchsorted(X, X+L, side = 'right') - 1).tolist())

for i in range(U):

    next_x.append([next_x[i][next_x[i][n]] for n in range(N)])



def days(a,b):

    a -= 1

    b -= 1

    if b < a:

        a,b = b,a

    # 到着できない範囲で最大限進む

    result = 0

    for n in range(U,-1,-1):

        c = next_x[n][a]

        if c < b:

            a = c

            result += 1 << n

    return result + 1



Q = int(eval(input()))

for _ in range(Q):

    a,b = list(map(int,input().split()))

    print((days(a,b)))

import sys

read = sys.stdin.buffer.read

readline = sys.stdin.buffer.readline

readlines = sys.stdin.buffer.readlines



import numpy as np



N = int(readline())

X = np.array(readline().split(),np.int64)

L = int(readline())

Q = int(readline())

AB = np.array(read().split(),np.int64).reshape(-1,2)



AB -= 1

AB.sort(axis = 1)

A = AB[:,0]; B = AB[:,1]



# 2^n 日あれば、どこまでいけるのか



U = 20

dp = [np.full(N,N-1,np.int64) for _ in range(U)]



dp[0] = np.searchsorted(X, X + L, side = 'right') - 1



for n in range(1,U):

    dp[n] = dp[n-1][dp[n-1]]



days = np.ones(Q,np.int64)

for n in reversed(list(range(U))):

    x = dp[n][A]

    bl = x < B

    days[bl] += (1 << n)

    A[bl] = x[bl]

print(('\n'.join(map(str,days))))
import sys

input = sys.stdin.readline
import numpy as np

N = int(eval(input()))
X = np.array(input().split(), dtype=np.int64)
L = int(eval(input()))
U = N.bit_length()
# 各ホテルから、2^n回でどこまで行けるか
next_x = []
next_x.append((np.searchsorted(X, X + L, side="right") - 1).tolist())
for i in range(U):
    next_x.append([next_x[i][next_x[i][n]] for n in range(N)])


def days(a, b):
    a -= 1
    b -= 1
    if b < a:
        a, b = b, a
    # 到着できない範囲で最大限進む
    result = 0
    for n in range(U, -1, -1):
        c = next_x[n][a]
        if c < b:
            a = c
            result += 1 << n
    return result + 1


Q = int(eval(input()))
for _ in range(Q):
    a, b = list(map(int, input().split()))
    print((days(a, b)))

import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np

N = int(readline())
X = np.array(readline().split(), np.int64)
L = int(readline())
Q = int(readline())
AB = np.array(read().split(), np.int64).reshape(-1, 2)
AB -= 1
AB.sort(axis=1)
A = AB[:, 0]
B = AB[:, 1]
# 2^n 日あれば、どこまでいけるのか
U = 20
dp = [np.full(N, N - 1, np.int64) for _ in range(U)]
dp[0] = np.searchsorted(X, X + L, side="right") - 1
for n in range(1, U):
    dp[n] = dp[n - 1][dp[n - 1]]
days = np.ones(Q, np.int64)
for n in reversed(list(range(U))):
    x = dp[n][A]
    bl = x < B
    days[bl] += 1 << n
    A[bl] = x[bl]
print(("\n".join(map(str, days))))

-input = sys.stdin.readline +read = sys.stdin.buffer.read +readline = sys.stdin.buffer.readline +readlines = sys.stdin.buffer.readlines -N = int(eval(input())) -X = np.array(input().split(), dtype=np.int64) -L = int(eval(input())) -U = N.bit_length() -# 各ホテルから、2^n回でどこまで行けるか -next_x = [] -next_x.append((np.searchsorted(X, X + L, side="right") - 1).tolist()) -for i in range(U): -    next_x.append([next_x[i][next_x[i][n]] for n in range(N)]) - - -def days(a, b): -    a -= 1 -    b -= 1 -    if b < a: -        a, b = b, a -    # 到着できない範囲で最大限進む -    result = 0 -    for n in range(U, -1, -1): -        c = next_x[n][a] -        if c < b: -            a = c -            result += 1 << n -    return result + 1 - - -Q = int(eval(input())) -for _ in range(Q): -    a, b = list(map(int, input().split())) -    print((days(a, b))) +N = int(readline()) +X = np.array(readline().split(), np.int64) +L = int(readline()) +Q = int(readline()) +AB = np.array(read().split(), np.int64).reshape(-1, 2) +AB -= 1 +AB.sort(axis=1) +A = AB[:, 0] +B = AB[:, 1] +# 2^n 日あれば、どこまでいけるのか +U = 20 +dp = [np.full(N, N - 1, np.int64) for _ in range(U)] +dp[0] = np.searchsorted(X, X + L, side="right") - 1 +for n in range(1, U): +    dp[n] = dp[n - 1][dp[n - 1]] +days = np.ones(Q, np.int64) +for n in reversed(list(range(U))): +    x = dp[n][A] +    bl = x < B +    days[bl] += 1 << n +    A[bl] = x[bl] +print(("\n".join(map(str, days))))