N hotels are located on a straight line. The coordinate of the i-th hotel (1 \leq i \leq N) is x_i.
Tak the traveler has the following two personal principles:
 - He never travels a distance of more than L in a single day.
 - He never sleeps in the open. That is, he must stay at a hotel at the end of a day.
You are given Q queries. The j-th (1 \leq j \leq Q) query is described by two distinct integers a_j and b_j.
For each query, find the minimum number of days that Tak needs to travel from the a_j-th hotel to the b_j-th hotel following his principles.
It is guaranteed that he can always travel from the a_j-th hotel to the b_j-th hotel, in any given input.

-----Constraints-----
 - 2 \leq N \leq 10^5
 - 1 \leq L \leq 10^9
 - 1 \leq Q \leq 10^5
 - 1 \leq x_i < x_2 < ... < x_N \leq 10^9
 - x_{i+1} - x_i \leq L
 - 1 \leq a_j,b_j \leq N
 - a_j \neq b_j
 - N,\,L,\,Q,\,x_i,\,a_j,\,b_j are integers.

-----Partial Score-----
 - 200 points will be awarded for passing the test set satisfying N \leq 10^3 and Q \leq 10^3.

-----Input-----
The input is given from Standard Input in the following format:
N
x_1 x_2 ... x_N
L
Q
a_1 b_1
a_2 b_2
:
a_Q b_Q

-----Output-----
Print Q lines.
The j-th line (1 \leq j \leq Q) should contain the minimum number of days that Tak needs to travel from the a_j-th hotel to the b_j-th hotel.

-----Sample Input-----
9
1 3 6 13 15 18 19 29 31
10
4
1 8
7 3
6 7
8 5

-----Sample Output-----
4
2
1
2

For the 1-st query, he can travel from the 1-st hotel to the 8-th hotel in 4 days, as follows:
 - Day 1: Travel from the 1-st hotel to the 2-nd hotel. The distance traveled is 2.
 - Day 2: Travel from the 2-nd hotel to the 4-th hotel. The distance traveled is 10.
 - Day 3: Travel from the 4-th hotel to the 7-th hotel. The distance traveled is 6.
 - Day 4: Travel from the 7-th hotel to the 8-th hotel. The distance traveled is 10.

Difficulty: HARD

Solutions:
from bisect import bisect
n = int(input())
x = list(map(int, input().split()))
l = int(input())
q = int(input())
r = [[i for i in range(n)] for _ in range(18)]
for j in range(n):
	r[0][j] = bisect(x, x[j] + l) - 1
for i in range(1, 18):
	for j in range(n):
		r[i][j] = r[i - 1][r[i - 1][j]]

def search(x, y):
	res = 0
	cur = x
	i = 17
	while True:
		if i == 0 and r[i][cur] >= y:
			return res + 1
		if r[i][cur] < y:
			cur = r[i][cur]
			res += 1 << i
			continue
		i -= 1
for _ in range(q):
	(a, b) = map(int, input().split())
	print(search(min(a, b) - 1, max(a, b) - 1))


import sys

def I():
	return int(sys.stdin.readline().rstrip())

def MI():
	return map(int, sys.stdin.readline().rstrip().split())

def LI():
	return list(map(int, sys.stdin.readline().rstrip().split()))
N = I()
x = LI()
L = I()
from bisect import bisect_right
arrive = [[0] * N for _ in range(30)]
for k in range(30):
	if k == 0:
		for i in range(N):
			arrive[0][i] = bisect_right(x, x[i] + L) - 1
	else:
		for i in range(N):
			arrive[k][i] = arrive[k - 1][arrive[k - 1][i]]

def query(a, b):
	a -= 1
	b -= 1
	ans = 1
	for k in range(29, -1, -1):
		if arrive[k][a] >= b:
			continue
		else:
			a = arrive[k][a]
			ans += 1 << k
	print(ans)
Q = I()
for i in range(Q):
	(a, b) = MI()
	if a > b:
		(a, b) = (b, a)
	query(a, b)


from bisect import bisect_left, bisect_right
N = int(input())
x = list(map(int, input().split()))
L = int(input())
n = N.bit_length() + 1
next_hotel = [[0] * n for _ in range(N)]
for i in range(N):
	index = bisect_right(x, x[i] + L) - 1
	if index == i:
		next_hotel[i][0] = N
	else:
		next_hotel[i][0] = index
for i in range(1, n):
	for j in range(N):
		if next_hotel[j][i - 1] < N:
			index = next_hotel[next_hotel[j][i - 1]][i - 1]
			if index == j:
				next_hotel[j][i] = N
			else:
				next_hotel[j][i] = index
		else:
			next_hotel[j][i] = N

def count(a, b):
	if a > b:
		(a, b) = (b, a)
	res = 0
	for i in range(n):
		if a >= b:
			return res
		c = max(0, bisect_left(next_hotel[a], b) - 1)
		a = next_hotel[a][c]
		res += 2 ** c
Q = int(input())
for _ in range(Q):
	(a, b) = map(int, input().split())
	print(count(a - 1, b - 1))


import bisect
n = int(input())
x = list(map(int, input().split()))
l = int(input())
q = int(input())
info = [list(map(int, input().split())) for i in range(q)]
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 sys
input = sys.stdin.readline
from bisect import bisect
n = int(input())
x = list(map(int, input().split()))
l = int(input())
m = 20
par = [[-1] * n for i in range(m)]
for i in range(n):
	j = bisect(x, x[i] + l) - 1
	par[0][i] = j
for i in range(m - 1):
	for j in range(n):
		par[i + 1][j] = par[i][par[i][j]]

def hoge(x, y):
	k = 0
	for i in range(m)[::-1]:
		if par[i][x] < y:
			k += 1 << i
			x = par[i][x]
	return k + 1
q = int(input())
ans = []
for i in range(q):
	(a, b) = map(int, input().split())
	(a, b) = (a - 1, b - 1)
	if a > b:
		(a, b) = (b, a)
	print(hoge(a, b))


import sys
input = sys.stdin.readline
from bisect import bisect_right
n = int(input())
X = tuple(map(int, input().split()))
l = int(input())
q = int(input())
D = [[0] * n for _ in range(18)]
for i in range(n):
	D[0][i] = bisect_right(X, X[i] + l) - 1
for k in range(1, 18):
	for i in range(n):
		D[k][i] = D[k - 1][D[k - 1][i]]

def query(a, b):
	ret = 0
	while True:
		for k in range(18):
			if D[k][a] >= b:
				break
		if k == 0:
			ret += 1
			return ret
		k -= 1
		ret += pow(2, k)
		a = D[k][a]
for _ in range(q):
	(a, b) = map(int, input().split())
	if a > b:
		(a, b) = (b, a)
	a -= 1
	b -= 1
	print(query(a, b))


from collections import deque
from bisect import bisect_right, bisect_left
N = int(input())
x = list(map(int, input().split()))
L = int(input())
K = 0
tmp = 1
while tmp <= N:
	tmp *= 2
	K += 1
parent = [[None] * N for _ in range(K)]
parent[0][N - 1] = N - 1
for i in range(N - 1):
	d = bisect_right(x, x[i] + L)
	parent[0][i] = d - 1
for k in range(1, K):
	for i in range(N):
		parent[k][i] = parent[k - 1][parent[k - 1][i]]
Q = int(input())
for _ in range(Q):
	ans = 0
	(a, b) = [int(x) - 1 for x in input().split()]
	if a > b:
		(a, b) = (b, a)
	for i in range(K - 1, -1, -1):
		if parent[i][a] < b:
			a = parent[i][a]
			ans += pow(2, i)
	print(ans + 1)


def examE():
	N = I()
	X = LI()
	L = I()
	Q = I()
	n = N.bit_length() + 1
	dp = [[0] * n for _ in range(N)]
	for i in range(N):
		dp[i][0] = bisect.bisect_right(X, X[i] + L) - 1
	for i in range(1, n):
		for j in range(N):
			if dp[j][i - 1] < N:
				index = dp[dp[j][i - 1]][i - 1]
				if index == j:
					dp[j][i] = N
				else:
					dp[j][i] = index
			else:
				dp[j][i] = N

	def fast_day(a, b):
		if a > b:
			(a, b) = (b, a)
		res = 0
		for i in range(n):
			if a >= b:
				return res
			c = max(0, bisect.bisect_left(dp[a], b) - 1)
			a = dp[a][c]
			res += 2 ** c
	for _ in range(Q):
		(a, b) = list(map(int, input().split()))
		print(fast_day(a - 1, b - 1))
import sys, copy, bisect, itertools, heapq, math
from heapq import heappop, heappush, heapify
from collections import Counter, defaultdict, deque

def I():
	return int(sys.stdin.readline())

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LS():
	return sys.stdin.readline().split()

def S():
	return sys.stdin.readline().strip()
mod = 10 ** 9 + 7
inf = float('inf')
examE()


from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, groupby
import sys
import bisect
import string
import math
import time
import random

def S_():
	return input()

def LS():
	return [i for i in input().split()]

def I():
	return int(input())

def MI():
	return map(int, input().split())

def LI():
	return [int(i) for i in input().split()]

def LI_():
	return [int(i) - 1 for i in input().split()]

def NI(n):
	return [int(input()) for i in range(n)]

def NI_(n):
	return [int(input()) - 1 for i in range(n)]

def StoI():
	return [ord(i) - 97 for i in input()]

def ItoS(nn):
	return chr(nn + 97)

def LtoS(ls):
	return ''.join([chr(i + 97) for i in ls])

def GI(V, E, Directed=False, index=0):
	org_inp = []
	g = [[] for i in range(n)]
	for i in range(E):
		inp = LI()
		org_inp.append(inp)
		if index == 0:
			inp[0] -= 1
			inp[1] -= 1
		if len(inp) == 2:
			(a, b) = inp
			g[a].append(b)
			if not Directed:
				g[b].append(a)
		elif len(inp) == 3:
			(a, b, c) = inp
			aa = (inp[0], inp[2])
			bb = (inp[1], inp[2])
			g[a].append(bb)
			if not Directed:
				g[b].append(aa)
	return (g, org_inp)

def bit_combination(k, n=2):
	rt = []
	for tb in range(n ** k):
		s = [tb // n ** bt % n for bt in range(k)]
		rt += [s]
	return rt

def show(*inp, end='\n'):
	if show_flg:
		print(*inp, end=end)
YN = ['Yes', 'No']
mo = 10 ** 9 + 7
inf = float('inf')
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
input = lambda : sys.stdin.readline().rstrip()

def ran_input():
	import random
	n = random.randint(4, 16)
	(rmin, rmax) = (1, 10)
	a = [random.randint(rmin, rmax) for _ in range(n)]
	return (n, a)
show_flg = False
show_flg = True
ans = 0
n = I()
m = n.bit_length()
x = LI()
L = I()
q = I()
r = [0] * n
for i in range(n):
	r[i] = bisect.bisect(x, x[i] + L) - 1
nb = [r]
nx = [0] * n
for k in range(m):
	nx = [0] * n
	for i in range(n):
		nx[i] = r[r[i]]
	nb.append(nx)
	r = nx
for _ in range(q):
	(a, b) = LI_()
	if a > b:
		(a, b) = (b, a)
	t = 0
	for p in range(m, -1, -1):
		if nb[p][a] < b:
			t += 1 << p
			a = nb[p][a]
	print(t + 1)


N = int(input())
(*X,) = map(int, input().split())
L = int(input())
K = 20
D = [[N] * (K + 1) for i in range(N)]
j = N - 1
for i in range(N - 1, -1, -1):
	while j > 0 and X[j] - X[i] > L:
		j -= 1
	D[i][0] = j
for k in range(K):
	for i in range(N):
		if D[i][k] != N:
			D[i][k + 1] = D[D[i][k]][k]

def solve(a, b):
	if not a < b:
		(a, b) = (b, a)
	res = 1
	for k in range(K, -1, -1):
		if D[a][k] < b:
			a = D[a][k]
			res += 2 ** k
	return res
Q = int(input())
ans = []
for i in range(Q):
	(a, b) = map(int, input().split())
	ans.append(solve(a - 1, b - 1))
print(*ans, sep='\n')


import bisect
import sys
input = sys.stdin.readline

def calc():
	n = int(input())
	arr = list(map(int, input().split()))
	l = int(input())
	pos = 0
	dbl = [[0] * (n + 1)]
	for i in range(n):
		dbl[0][i + 1] = bisect.bisect_right(arr, arr[i] + l)
	for _ in range(n.bit_length() - 1):
		tmp = [0] * (n + 1)
		for i in range(n + 1):
			tmp[i] = dbl[-1][dbl[-1][i]]
		dbl.append(tmp)
	q = int(input())
	for _ in range(q):
		(a, b) = map(int, input().split())
		if a > b:
			(a, b) = (b, a)
		l = 0
		r = b - a + 1
		while r - l != 1:
			mid = (l + r) // 2
			tmp = a
			for i in range(mid.bit_length()):
				if mid & 1 << i:
					tmp = dbl[i][tmp]
			if tmp >= b:
				r = mid
			else:
				l = mid
		print(r)
calc()


import sys
input = sys.stdin.readline
import numpy as np
N = int(input())
X = np.array(input().split(), dtype=np.int64)
L = int(input())
U = N.bit_length()
next_x = []
next_x.append(np.searchsorted(X, X + L, side='right') - 1)
for i in range(U):
	next_x.append(next_x[i][next_x[i]])

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(input())
for _ in range(Q):
	(a, b) = map(int, input().split())
	print(days(a, b))


import sys
input = sys.stdin.readline
import bisect
n = int(input())
X = list(map(int, input().split()))
l = int(input())
U = 17
dp = [[0] * n for _ in range(U + 1)]
for (i, x) in enumerate(X):
	t = bisect.bisect_left(X, x + l)
	dp[0][i] = bisect.bisect_right(X, x + l) - 1
for k in range(U):
	for i in range(n):
		dp[k + 1][i] = dp[k][dp[k][i]]

def test(x, a, b):
	for i in range(U, -1, -1):
		if x >> i & 1:
			a = dp[i][a]
	return a >= b

def solve(a, b):
	if a > b:
		(a, b) = (b, a)
	ng = 0
	ok = n - 1
	while ok - ng > 1:
		mid = (ng + ok) // 2
		if test(mid, a, b):
			ok = mid
		else:
			ng = mid
	print(ok)
q = int(input())
for _ in range(q):
	(a, b) = map(int, input().split())
	a -= 1
	b -= 1
	solve(a, b)


from bisect import bisect
N = int(input())
xs = list(map(int, input().split()))
L = int(input())
Q = int(input())
qs = [tuple(map(lambda x: int(x) - 1, input().split())) for i in range(Q)]
K = len(bin(N)) - 1
dp = [[None] * N for i in range(K)]
for (i, x) in enumerate(xs):
	dp[0][i] = bisect(xs, x + L) - 1
for k in range(K - 1):
	for i in range(N):
		dp[k + 1][i] = dp[k][dp[k][i]]

def enough(fr, to, n):
	now = fr
	bn = bin(n)
	ln = len(bn) - 2
	for (i, c) in enumerate(bn[2:]):
		if c == '0':
			continue
		now = dp[ln - 1 - i][now]
		if now >= to:
			return True
	return False
ans = []
for (a, b) in qs:
	if a > b:
		(a, b) = (b, a)
	ok = N
	ng = 0
	while ok - ng > 1:
		m = (ok + ng) // 2
		if enough(a, b, m):
			ok = m
		else:
			ng = m
	ans.append(ok)
print(*ans, sep='\n')


import sys
input = sys.stdin.readline
import bisect

def main():
	n = int(input())
	X = list(map(int, input().split()))
	l = int(input())
	U = 17
	dp = [[0] * n for _ in range(U + 1)]
	for (i, x) in enumerate(X):
		t = bisect.bisect_left(X, x + l)
		dp[0][i] = bisect.bisect_right(X, x + l) - 1
	for k in range(U):
		for i in range(n):
			dp[k + 1][i] = dp[k][dp[k][i]]
	q = int(input())
	for _ in range(q):
		(a, b) = map(int, input().split())
		a -= 1
		b -= 1
		if a > b:
			(a, b) = (b, a)
		res = 1
		for k in range(U, -1, -1):
			if dp[k][a] < b:
				a = dp[k][a]
				res += 1 << k
		print(res)
main()


import bisect
n = int(input())
x = [int(item) for item in input().split()]
l = int(input())
q = int(input())
ab = []
for i in range(q):
	(a, b) = [int(item) for item in input().split()]
	a -= 1
	b -= 1
	if a > b:
		(a, b) = (b, a)
	ab.append((a, b))
dt = [[0] * n for _ in range(18)]
for (i, item) in enumerate(x):
	dt[0][i] = bisect.bisect_right(x, item + l) - 1
for i in range(1, 18):
	for j in range(n):
		dt[i][j] = dt[i - 1][dt[i - 1][j]]
for (a, b) in ab:
	days = 0
	if a == b:
		print(days)
		continue
	for i in range(17, -1, -1):
		if dt[i][a] < b:
			a = dt[i][a]
			days += 2 ** i
	print(days + 1)


import bisect
n = int(input())
arr = list(map(int, input().split()))
l = int(input())
pos = 0
dbl = [[0] * (n + 1)]
for i in range(n):
	dbl[0][i + 1] = bisect.bisect_right(arr, arr[i] + l)
for _ in range(20):
	tmp = [0] * (n + 1)
	for i in range(n + 1):
		tmp[i] = dbl[-1][dbl[-1][i]]
	dbl.append(tmp)
q = int(input())
for _ in range(q):
	(a, b) = map(int, input().split())
	if a > b:
		(a, b) = (b, a)
	l = 0
	r = b - a + 1
	while r - l != 1:
		mid = (l + r) // 2
		tmp = a
		for i in range(20):
			if mid & 1 << i:
				tmp = dbl[i][tmp]
		if tmp >= b:
			r = mid
		else:
			l = mid
	print(r)


n = int(input())
x = list(map(int, input().split()))
l = int(input())
q = int(input())
ab = [list(map(int, input().split())) for i in range(q)]
keta = len(format(n + 1, 'b'))
nxt = [[0 for _ in range(n)] for _ in range(keta)]
import bisect
for i in range(n):
	num = x[i] + l
	ind = bisect.bisect_right(x, num)
	nxt[0][i] = ind - 1
for k in range(1, keta):
	for i in range(n):
		nxt[k][i] = nxt[k - 1][nxt[k - 1][i]]

def solve(s, g, day):
	bi = format(day, 'b')
	keta = len(bi) - 1
	for b in bi:
		if b == '1':
			s = nxt[keta][s]
		keta -= 1
	return s >= g
for (a, b) in ab:
	s = min(a, b)
	g = max(a, b)
	l = 0
	r = n
	while r - l > 1:
		mid = (l + r) // 2
		if solve(s - 1, g - 1, mid):
			r = mid
		else:
			l = mid
	print(r)


import bisect
N = int(input())
x = list(map(int, input().split()))
L = int(input())
dest = []
dest_1 = [0] * N
for i in range(N):
	dest_1[i] = bisect.bisect_left(x, x[i] + L + 0.5) - 1
dest.append(dest_1)
for i in range(1, len(bin(N - 1)) - 1):
	dest_prev = dest[i - 1]
	dest_i = [0] * N
	for j in range(N):
		dest_i[j] = dest_prev[dest_prev[j]]
	dest.append(dest_i)
Q = int(input())
for _ in range(Q):
	(a, b) = list(map(int, input().split()))
	a -= 1
	b -= 1
	if a > b:
		(a, b) = (b, a)
	k = len(dest) - 1
	ans = 0
	while True:
		d = dest[k][a]
		if d >= b:
			if k > 0:
				k -= 1
			else:
				ans += 1
				break
		else:
			ans += 2 ** k
			a = d
	print(ans)


from bisect import bisect_right
from math import log
N = int(input())
X = list(map(int, input().split()))
L = int(input())
R = [[-1] * N for i in range(int(log(N, 2) + 1))]
for i in range(N):
	R[0][i] = bisect_right(X, X[i] + L) - 1
for k in range(1, len(R)):
	for i in range(N):
		R[k][i] = R[k - 1][R[k - 1][i]]
Q = int(input())
for q in range(Q):
	(a, b) = map(int, input().split())
	(a, b) = (min(a, b) - 1, max(a, b) - 1)
	ans = 0
	for k in range(len(R))[::-1]:
		if R[k][a] < b:
			a = R[k][a]
			ans += 2 ** k
	print(ans + 1)


import bisect
n = int(input())
x = [int(s) - 1 for s in input().split()]
l = int(input())
q = int(input())
p = [[0] * 17 for _ in range(n)]
for i in range(n):
	p[i][0] = bisect.bisect_right(x, x[i] + l) - 1
for i in range(1, 17):
	for j in range(n):
		p[j][i] = p[p[j][i - 1]][i - 1]
for _ in range(q):
	(a, b) = sorted((int(s) - 1 for s in input().split()))
	r = 0
	for i in reversed(range(17)):
		if p[a][i] < b:
			a = p[a][i]
			r += 1 << i
	print(r + 1)


from bisect import bisect_right
N = int(input())
X = list(map(int, input().split()))
L = int(input())
P = [[0] * N for i in range(30)]
for i in range(N):
	q = bisect_right(X, X[i] + L)
	P[0][i] = q - 1
for i in range(1, 30):
	for j in range(N):
		P[i][j] = P[i - 1][P[i - 1][j]]
Q = int(input())
for i in range(Q):
	(a, b) = map(int, input().split())
	if a > b:
		(a, b) = (b, a)
	(a, b) = (a - 1, b - 1)
	num = 0
	for j in range(29, -1, -1):
		if P[j][a] < b:
			a = P[j][a]
			num += 2 ** j
	print(num + 1)


from bisect import bisect_right
import sys
input = sys.stdin.readline
N = int(input())
x = list(map(int, input().split()))
L = int(input())
log = 1
while 1 << log < N:
	log += 1
doubling = [[0] * (log + 1) for _ in range(N)]
for i in range(N):
	j = bisect_right(x, x[i] + L) - 1
	doubling[i][0] = j
for l in range(1, log + 1):
	for i in range(N):
		doubling[i][l] = doubling[doubling[i][l - 1]][l - 1]
Q = int(input())
for _ in range(Q):
	(a, b) = map(int, input().split())
	a -= 1
	b -= 1
	if a > b:
		(a, b) = (b, a)
	ans = 0
	for l in range(log, -1, -1):
		if doubling[a][l] < b:
			ans += 1 << l
			a = doubling[a][l]
	print(ans + 1)


import bisect
n = int(input())
x = list(map(int, input().split()))
l = int(input())
q = int(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
import math
N = int(input())
x = list(map(int, input().split()))
L = int(input())
m = int(math.log(max(x), 2) + 1)
r = [[-1] * N for k in range(m)]
for i in range(N):
	base = x[i] + L
	p = bisect.bisect_right(x, base)
	r[0][i] = p - 1
for k in range(m - 1):
	for i in range(N):
		r[k + 1][i] = r[k][r[k][i]]

def isOK(mid):
	now = a
	pp = int(math.log(mid, 2) + 1)
	for i in range(pp):
		if mid >> i & 1:
			now = r[i][now]
	if now >= b:
		return True
	else:
		return False
Q = int(input())
for i in range(Q):
	(a, b) = map(int, input().split())
	(a, b) = (a - 1, b - 1)
	if a > b:
		(a, b) = (b, a)
	ng = 0
	ok = 2 ** m
	while abs(ok - ng) > 1:
		mid = int((ok + ng) / 2)
		if isOK(mid):
			ok = mid
		else:
			ng = mid
	print(ok)


import sys, bisect
input = sys.stdin.readline
N = int(input())
x = list(map(int, input().split()))
L = int(input())
doubling = [[-1 for i in range(N)] for j in range(20)]
for i in range(N):
	npos = x[i] + L
	index = bisect.bisect_right(x, npos)
	doubling[0][i] = index - 1
for i in range(1, 20):
	for j in range(N):
		doubling[i][j] = doubling[i - 1][doubling[i - 1][j]]
forward = [[-1 for i in range(N)] for j in range(20)]
for i in range(N):
	forward[0][i] = i
for i in range(1, 20):
	for j in range(N):
		forward[i][j] = doubling[i - 1][forward[i - 1][j]]
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	a -= 1
	b -= 1
	if a > b:
		(a, b) = (b, a)
	res = 0
	for i in range(19, -1, -1):
		if b > forward[i][a]:
			a = doubling[i][a]
			res += 2 ** i
	print(res)


import bisect
import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
d = int(input())
graph = [[0 for i in range(n + 1)] for j in range(18)]
for i in range(n):
	x = bisect.bisect_right(a, a[i] + d)
	graph[0][i + 1] = x
for j in range(1, 18):
	for i in range(n):
		t = graph[j - 1][i + 1]
		graph[j][i + 1] = graph[j - 1][t]
q = int(input())
for _ in range(q):
	(x, y) = map(int, input().split())
	(x, y) = (min(x, y), max(x, y))
	ans = 0
	for j in range(18)[::-1]:
		if graph[j][x] < y:
			ans += 2 ** j
			x = graph[j][x]
		if j == 0 and x < y:
			ans += 1
	print(ans)


import sys
input = sys.stdin.readline
from bisect import *

def judge(a, b, x):
	now = a
	c = 0
	while x > 0:
		if x & 1:
			now = dp[c][now]
		x >>= 1
		c += 1
	return now >= b

def binary_search(a, b):
	(l, r) = (0, N - 1)
	while l <= r:
		m = (l + r) // 2
		if judge(a, b, m):
			r = m - 1
		else:
			l = m + 1
	return l
N = int(input())
x = list(map(int, input().split()))
L = int(input())
log_size = 22
dp = [[0] * N for _ in range(log_size)]
for i in range(N):
	dp[0][i] = bisect_right(x, x[i] + L) - 1
for i in range(1, log_size):
	for j in range(N):
		dp[i][j] = dp[i - 1][dp[i - 1][j]]
Q = int(input())
for _ in range(Q):
	(a, b) = map(int, input().split())
	(a, b) = (min(a, b) - 1, max(a, b) - 1)
	print(binary_search(a, b))


from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect

def LI():
	return [int(x) for x in sys.stdin.buffer.readline().split()]

def I():
	return int(sys.stdin.buffer.readline())

def LS():
	return [list(x) for x in sys.stdin.readline().split()]

def S():
	res = list(sys.stdin.readline())
	if res[-1] == '\n':
		return res[:-1]
	return res

def IR(n):
	return [I() for i in range(n)]

def LIR(n):
	return [LI() for i in range(n)]

def SR(n):
	return [S() for i in range(n)]

def LSR(n):
	return [LS() for i in range(n)]
sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
	n = I()
	x = LI()
	f = [[] for i in range(n)]
	l = I()
	for i in range(n):
		xi = x[i]
		j = bisect.bisect_right(x, l + xi) - 1
		f[i].append(j)
	h = int(math.log(n, 2)) + 1
	for j in range(h - 1):
		for i in range(n):
			f[i].append(f[f[i][j]][j])
	q = I()
	for _ in range(q):
		(a, b) = LI()
		a -= 1
		b -= 1
		if b < a:
			(a, b) = (b, a)
		ans = 0
		for i in range(h)[::-1]:
			if f[a][i] < b:
				a = f[a][i]
				ans += 1 << i
		print(ans + 1)
	return
solve()


from collections import defaultdict, deque
import sys, heapq, bisect, math, itertools, string, queue, datetime
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
mod = 10 ** 9 + 7

def inpl():
	return list(map(int, input().split()))

def inpls():
	return list(input().split())
N = int(input())
xx = inpl()
L = int(input())
K = N.bit_length()
db_r = [[0] * K for i in range(N)]
for (i, x) in enumerate(xx):
	ind = bisect.bisect_right(xx, x + L)
	db_r[i][0] = ind - 1
for k in range(1, K):
	for i in range(N):
		db_r[i][k] = db_r[db_r[i][k - 1]][k - 1]

def check(a, b, d):
	L = d.bit_length()
	for k in range(L):
		if d & 1 << k:
			a = db_r[a][k]
	return a >= b
Q = int(input())
for i in range(Q):
	(a, b) = inpl()
	a -= 1
	b -= 1
	(a, b) = (min(a, b), max(a, b))
	OK = N
	NG = 0
	while OK - NG > 1:
		mid = (OK + NG) // 2
		if check(a, b, mid):
			OK = mid
		else:
			NG = mid
	print(OK)


import sys

def input():
	return sys.stdin.readline().strip()

def mapint():
	return map(int, input().split())
sys.setrecursionlimit(10 ** 9)
N = int(input())
Xs = list(mapint())
L = int(input())
from bisect import bisect_right
nex = [[0] * N for _ in range(32)]
for i in range(N):
	now = Xs[i]
	idx = bisect_right(Xs, now + L) - 1
	nex[0][i] = idx
for i in range(1, 32):
	for j in range(N):
		nex[i][j] = nex[i - 1][nex[i - 1][j]]
Q = int(input())
for _ in range(Q):
	(a, b) = mapint()
	if a > b:
		(a, b) = (b, a)
	(a, b) = (a - 1, b - 1)
	cnt = 0
	for i in range(31, -1, -1):
		if nex[i][a] < b:
			cnt += 2 ** i
			a = nex[i][a]
	if a != b:
		cnt += 1
	print(cnt)


import sys
input = sys.stdin.readline
from bisect import bisect
N = int(input())
X = [int(i) for i in input().split()]
L = int(input())
Q = int(input())
T = []
for i in range(Q):
	(a, b) = map(int, input().split())
	if a > b:
		(a, b) = (b, a)
	T.append((a - 1, b - 1))
F = [0] * N
for i in range(N):
	F[i] = bisect(X, X[i] + L) - 1
dp = [[N - 1] * N for i in range(18)]
for i in range(N):
	dp[0][i] = F[i]
for c in range(1, 18):
	for i in range(N):
		dp[c][i] = dp[c - 1][dp[c - 1][i]]

def f(a, b):
	num = 0
	t = a
	while True:
		for i in range(18):
			if dp[i][t] >= b:
				s = i
				break
		if s == 0:
			num += 1
			break
		num += pow(2, s - 1)
		t = dp[s - 1][t]
	print(num)
for (a, b) in T:
	f(a, b)


from bisect import bisect
inpl = lambda : list(map(int, input().split()))
N = int(input())
X = inpl()
L = int(input())
Q = int(input())
R = [[0] * N for k in range(17)]
for i in range(N):
	R[0][i] = bisect(X, X[i] + L) - 1
for k in range(16):
	for i in range(N):
		R[k + 1][i] = R[k][R[k][i]]

def reach(a, d):
	O = format(d, 'b').zfill(17)[::-1]
	for k in range(16, -1, -1):
		if O[k] == '1':
			a = R[k][a]
	return a

def bisearch(a, b):
	(a, b) = (a - 1, b - 1)
	if b < a:
		(a, b) = (b, a)
	OK = b - a
	NG = 0
	while abs(OK - NG) > 1:
		mid = (OK + NG) // 2
		if reach(a, mid) >= b:
			OK = mid
		else:
			NG = mid
	return OK
print(*[bisearch(*inpl()) for _ in range(Q)], sep='\n')


from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
from operator import mul
sys.setrecursionlimit(2147483647)
INF = 10 ** 20

def LI():
	return list(map(int, sys.stdin.buffer.readline().split()))

def I():
	return int(sys.stdin.buffer.readline())

def LS():
	return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()

def S():
	return sys.stdin.buffer.readline().rstrip().decode('utf-8')

def IR(n):
	return [I() for i in range(n)]

def LIR(n):
	return [LI() for i in range(n)]

def SR(n):
	return [S() for i in range(n)]

def LSR(n):
	return [LS() for i in range(n)]

def SRL(n):
	return [list(S()) for i in range(n)]

def MSRL(n):
	return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007
n = I()
X = LI()
l = I()
log_n = (n - 1).bit_length()
doubling = [[n] * n for _ in range(log_n)]
for i in range(n - 1):
	doubling[0][i] = bisect_right(X, X[i] + l) - 1
for j in range(1, log_n):
	for k in range(n):
		if doubling[j - 1][k] == n:
			continue
		doubling[j][k] = doubling[j - 1][doubling[j - 1][k]]
q = I()
for _ in range(q):
	(a, b) = LI()
	if a > b:
		(a, b) = (b, a)
	a -= 1
	b -= 1
	ans = 0
	for m in range(log_n - 1, -1, -1):
		if doubling[m][a] < b:
			a = doubling[m][a]
			ans += 2 ** m
	print(ans + 1)


import sys
sys.setrecursionlimit(10 ** 6)
from bisect import bisect_left, bisect
n = int(input())
x = list(map(int, input().split()))
L = int(input())
t = n.bit_length()
prv = [n - 1] * n
for i in range(n):
	prv[i] = bisect(x, x[i] + L) - 1
kprv = [prv]
S = prv
for i in range(t - 1):
	kar = [n - 1] * n
	for j in range(n):
		kar[j] = S[S[j]]
	kprv.append(kar)
	S = kar
q = int(input())
for _ in range(q):
	(a, b) = map(lambda x: int(x) - 1, input().split())
	if a > b:
		(a, b) = (b, a)
	lef = 0
	rig = n - 1
	while rig - lef > 1:
		mid = (rig + lef) // 2
		p = mid.bit_length()
		now = a
		for i in range(p):
			if mid >> i & 1 == 1:
				now = kprv[i][now]
		if now >= b:
			rig = mid
		elif now < b:
			lef = mid
	print(rig)


from bisect import bisect_left, bisect_right
N = int(input())
xs = list(map(int, input().split()))
L = int(input())
Q = int(input())
ABs = [tuple(map(lambda x: int(x) - 1, input().split())) for _ in range(Q)]
logN = (N - 1).bit_length()
parentss = [[N - 1] * (logN + 1) for _ in range(N)]
for i in range(N - 1):
	iL = bisect_right(xs, xs[i] + L)
	parentss[i][0] = iL - 1
for d in range(1, logN + 1):
	for i in range(N - 1):
		parentss[i][d] = parentss[parentss[i][d - 1]][d - 1]
anss = []
for (A, B) in ABs:
	if A > B:
		(A, B) = (B, A)
	i = A
	ans = 1
	for d in reversed(range(logN + 1)):
		if parentss[i][d] < B:
			i = parentss[i][d]
			ans += 2 ** d
	anss.append(ans)
print('\n'.join(map(str, anss)))


import os
import sys
import numpy as np
if os.getenv('LOCAL'):
	sys.stdin = open('_in.txt', 'r')
sys.setrecursionlimit(2147483647)
INF = float('inf')
IINF = 10 ** 18
MOD = 10 ** 9 + 7
N = int(sys.stdin.readline())
X = list(map(int, sys.stdin.readline().split()))
L = int(sys.stdin.readline())
Q = int(sys.stdin.readline())
AB = [list(map(int, sys.stdin.readline().split())) for _ in range(Q)]
N += 2
X = [X[0]] + X + [X[-1]]
X = np.array(X, dtype=int)
dp = np.zeros((N.bit_length() + 1, N), dtype=int)
dp[0] = np.searchsorted(X, X + L, side='right') - 1
for d in range(1, N.bit_length() + 1):
	dp[d] = dp[d - 1][dp[d - 1]]
dp = dp.tolist()

def solve(l, r):
	ret = 0
	d = len(dp) - 1
	while l + 1 < r:
		while d > 0 and dp[d][l] >= r:
			d -= 1
		ret += 1 << d
		l = dp[d][l]
	if l < r:
		ret += 1
	return ret
ans = []
for (a, b) in AB:
	ans.append(solve(min(a, b), max(a, b)))
print(*ans, sep='\n')


import bisect
n = int(input())
x = [int(item) for item in input().split()]
l = int(input())
q = int(input())
ab = []
for i in range(q):
	(a, b) = [int(item) for item in input().split()]
	a -= 1
	b -= 1
	if a > b:
		(a, b) = (b, a)
	ab.append((a, b))
dt = [[0] * n for _ in range(40)]
for (i, item) in enumerate(x):
	dt[0][i] = i
	dt[1][i] = bisect.bisect_right(x, item + l) - 1
for i in range(2, 40):
	for j in range(n):
		dt[i][j] = dt[i - 1][dt[i - 1][j]]
for (a, b) in ab:
	days = 0
	is_ok = False
	while a < b:
		for i in range(0, 40):
			if dt[i][a] >= b:
				if i == 1:
					days += 1
					is_ok = True
				else:
					a = dt[i - 1][a]
					days += 2 ** (i - 2)
				break
		if is_ok:
			break
	print(days)


from bisect import bisect_left
INF = float('inf')

def check(a, b):
	(ng, ok) = (-1, N + 1)
	while ok - ng > 1:
		mid = (ng + ok) // 2
		now = a
		bit = 0
		x = mid
		while x:
			if x & 1:
				now = A[now][bit]
			bit += 1
			x >>= 1
		if b <= now:
			ok = mid
		else:
			ng = mid
	return ok
N = int(input())
x = list(map(int, input().split()))
K = N.bit_length() - 1
L = int(input())
A = [[INF] * (K + 1) for _ in range(N)]
for i in range(N):
	b = bisect_left(x, x[i] + L + 1)
	A[i][0] = b - 1
for k in range(K):
	for i in range(N):
		A[i][k + 1] = A[A[i][k]][k]
Q = int(input())
for _ in range(Q):
	(a, b) = map(lambda x: int(x) - 1, input().split())
	if a > b:
		(a, b) = (b, a)
	print(check(a, b))


import sys
sys.setrecursionlimit(10 ** 7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
from functools import partial, reduce
from operator import mul
prod = partial(reduce, mul)

def LI():
	return [int(x) for x in sys.stdin.readline().split()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def II():
	return int(sys.stdin.readline())

def SI():
	return input()
from bisect import bisect

def main():
	N = II()
	X = LI()
	X.append(INF)
	L = II()
	Q = II()
	AB = []
	for _ in range(Q):
		AB.append(LI_())
	Unreachs = [[] for _ in range(N)]
	for (i, x) in enumerate(X[:-1]):
		u = bisect(X, x + L)
		Unreachs[i].append(u)
	updated = True
	while updated:
		updated = False
		for i in range(N):
			u = Unreachs[Unreachs[i][-1] - 1][-1]
			updated = updated or u != Unreachs[i][-1]
			Unreachs[i].append(u)
	for (a, b) in AB:
		if a > b:
			(a, b) = (b, a)
		ans = 0
		while True:
			k = bisect(Unreachs[a], b) - 1
			if k < 0:
				ans += 1
				break
			ans += 2 ** k
			a = Unreachs[a][k] - 1
		print(ans)
	return 0
main()


import math
import itertools
import heapq
from sys import stdin, stdout, setrecursionlimit
from bisect import bisect, bisect_left, bisect_right
from collections import defaultdict, deque

def LM(t, r):
	return list(map(t, r))

def R():
	return stdin.readline()

def RS():
	return R().split()

def I():
	return int(R())

def F():
	return float(R())

def LI():
	return LM(int, RS())

def LF():
	return LM(float, RS())

def ONE_SL():
	return list(input())

def ONE_IL():
	return LM(int, ONE_SL())

def ALL_I():
	return map(int, stdin)

def ALL_IL():
	return LM(int, stdin)

def ap(f):
	return f.append

def pll(li):
	print('\n'.join(LM(str, li)))

def pljoin(li, s):
	print(s.join(li))

def main():
	N = I()
	X = LI()
	L = I()
	Q = I()
	r = [[0 for _ in range(100010)] for _ in range(20)]
	for i in range(N):
		r[0][i] = bisect_right(X, X[i] + L) - 1
	for i in range(1, 20):
		for j in range(N):
			r[i][j] = r[i - 1][r[i - 1][j]]
	for q in range(Q):
		(a, b) = LI()
		a -= 1
		b -= 1
		if a > b:
			(a, b) = (b, a)
		ans = 0
		now = a
		for i in range(0, 20)[::-1]:
			if r[i][now] < b:
				now = r[i][now]
				ans += 2 ** i
		print(ans + 1)
main()


import math
from bisect import bisect_left, bisect_right
N = int(input())
X = list(map(int, input().split()))
L = int(input())
Q = int(input())
Y = [list(map(int, input().split())) for _ in range(Q)]
LOGN = int(math.log(N) / math.log(2)) + 1
parent = [[-1] * N for _ in range(LOGN + 1)]
for k in range(LOGN + 1):
	for i in range(N):
		if k == 0:
			parent[k][i] = bisect_right(X, X[i] + L) - 1
		else:
			parent[k][i] = parent[k - 1][parent[k - 1][i]]

def find(a, b):
	num = 0
	u = a
	while True:
		k = 0
		for i in range(LOGN + 1):
			if parent[i][u] >= b:
				k = i
				break
		if k == 0:
			num += 1
			break
		num += pow(2, k - 1)
		u = parent[k - 1][u]
	return num
for (a, b) in Y:
	a -= 1
	b -= 1
	if a > b:
		(a, b) = (b, a)
	print(find(a, b))


import sys
input = sys.stdin.buffer.readline
import bisect
INF = float('inf')
from collections import defaultdict

def getlist():
	return list(map(int, input().split()))

def main():
	N = int(input())
	X = getlist()
	X.append(INF)
	L = int(input())
	double = [[0] * (N + 1) for i in range(20)]
	for i in range(N):
		p = bisect.bisect_left(X, X[i] + L + 1)
		double[0][i] = p - 1
	for i in range(20):
		double[i][N] = INF
	for i in range(1, 20):
		for j in range(N):
			double[i][j] = double[i - 1][double[i - 1][j]]
	Q = int(input())
	for i in range(Q):
		(a, b) = sorted(getlist())
		a -= 1
		b -= 1
		ans = 0
		for j in range(20):
			if double[19 - j][a] < b:
				a = double[19 - j][a]
				ans += 1 << 19 - j
		print(ans + 1)
main()