import bisect





n = int(eval(input()))

x = list(map(int, input().split()))

l = int(eval(input()))

q = int(eval(input()))

info = [list(map(int, input().split())) for i in range(q)]





#logテーブルを作成する

log_table = [[0]*n for i in range(17)]

for i in range(n):

    log_table[0][i] = bisect.bisect_right(x, x[i] + l) - 1

for j in range(1, 17):

    for i in range(n):

        log_table[j][i] = log_table[j-1][log_table[j-1][i]]



#二分探索で解を求める

def solve(_from, to, day):

    pos = _from

    i = 0

    while day:

        if day // 2 > 0:

            if day % 2 == 1:

                pos = log_table[i][pos]

            i += 1

            day = day // 2

        else:

            if day % 2 == 1:

                pos = log_table[i][pos]

            break

    if to <= pos:

        return True

    else:

        return False



#クエリに答える

for i in range(q):

    ok = n - 1

    ng = 0

    start, goal = info[i]

    start -= 1

    goal -= 1

    if start > goal:

        start, goal = goal, start

    while abs(ok - ng) > 1:

        mid = (ok + ng) // 2

        if solve(start, goal, mid):

            ok = mid

        else:

            ng = mid

    print(ok)
import bisect





n = int(eval(input()))

x = list(map(int, input().split()))

l = int(eval(input()))

q = int(eval(input()))

query = [list(map(int, input().split())) for i in range(q)]



log_size = n.bit_length() + 1

double = [[0] * n for i in range(log_size)]



for i in range(n):

    double[0][i] = bisect.bisect_right(x, x[i] + l) - 1



for k in range(1, log_size):

    for i in range(n):

        double[k][i] = double[k - 1][double[k - 1][i]]

        

for a, b in query:

    a -= 1

    b -= 1

    if a > b:

        a, b = b, a

    ans = 10 ** 18

    tmp = 0

    for k in range(log_size)[::-1]:

        if double[k][a] >= b:

            ans = min(ans, 2 ** k + tmp)

        else:

            a = double[k][a]

            tmp += 2 ** k

    print(ans)
import bisect

n = int(eval(input()))
x = list(map(int, input().split()))
l = int(eval(input()))
q = int(eval(input()))
info = [list(map(int, input().split())) for i in range(q)]
# logテーブルを作成する
log_table = [[0] * n for i in range(17)]
for i in range(n):
    log_table[0][i] = bisect.bisect_right(x, x[i] + l) - 1
for j in range(1, 17):
    for i in range(n):
        log_table[j][i] = log_table[j - 1][log_table[j - 1][i]]
# 二分探索で解を求める
def solve(_from, to, day):
    pos = _from
    i = 0
    while day:
        if day // 2 > 0:
            if day % 2 == 1:
                pos = log_table[i][pos]
            i += 1
            day = day // 2
        else:
            if day % 2 == 1:
                pos = log_table[i][pos]
            break
    if to <= pos:
        return True
    else:
        return False


# クエリに答える
for i in range(q):
    ok = n - 1
    ng = 0
    start, goal = info[i]
    start -= 1
    goal -= 1
    if start > goal:
        start, goal = goal, start
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        if solve(start, goal, mid):
            ok = mid
        else:
            ng = mid
    print(ok)

import bisect

n = int(eval(input()))
x = list(map(int, input().split()))
l = int(eval(input()))
q = int(eval(input()))
query = [list(map(int, input().split())) for i in range(q)]
log_size = n.bit_length() + 1
double = [[0] * n for i in range(log_size)]
for i in range(n):
    double[0][i] = bisect.bisect_right(x, x[i] + l) - 1
for k in range(1, log_size):
    for i in range(n):
        double[k][i] = double[k - 1][double[k - 1][i]]
for a, b in query:
    a -= 1
    b -= 1
    if a > b:
        a, b = b, a
    ans = 10**18
    tmp = 0
    for k in range(log_size)[::-1]:
        if double[k][a] >= b:
            ans = min(ans, 2**k + tmp)
        else:
            a = double[k][a]
            tmp += 2**k
    print(ans)

-info = [list(map(int, input().split())) for i in range(q)] -# logテーブルを作成する -log_table = [[0] * n for i in range(17)] +query = [list(map(int, input().split())) for i in range(q)] +log_size = n.bit_length() + 1 +double = [[0] * n for i in range(log_size)] -    log_table[0][i] = bisect.bisect_right(x, x[i] + l) - 1 -for j in range(1, 17): +    double[0][i] = bisect.bisect_right(x, x[i] + l) - 1 +for k in range(1, log_size): -        log_table[j][i] = log_table[j - 1][log_table[j - 1][i]] -# 二分探索で解を求める -def solve(_from, to, day): -    pos = _from -    i = 0 -    while day: -        if day // 2 > 0: -            if day % 2 == 1: -                pos = log_table[i][pos] -            i += 1 -            day = day // 2 +        double[k][i] = double[k - 1][double[k - 1][i]] +for a, b in query: +    a -= 1 +    b -= 1 +    if a > b: +        a, b = b, a +    ans = 10**18 +    tmp = 0 +    for k in range(log_size)[::-1]: +        if double[k][a] >= b: +            ans = min(ans, 2**k + tmp) -            if day % 2 == 1: -                pos = log_table[i][pos] -            break -    if to <= pos: -        return True -    else: -        return False - - -# クエリに答える -for i in range(q): -    ok = n - 1 -    ng = 0 -    start, goal = info[i] -    start -= 1 -    goal -= 1 -    if start > goal: -        start, goal = goal, start -    while abs(ok - ng) > 1: -        mid = (ok + ng) // 2 -        if solve(start, goal, mid): -            ok = mid -        else: -            ng = mid -    print(ok) +            a = double[k][a] +            tmp += 2**k +    print(ans)