import algorithm, future, hashes, macros, math, sequtils, sets, strutils, tables, times, unicode, queues

macro unpack(rhs: seq, cnt: static[int]): auto =
  let t = genSym(); result = quote do:(let `t` = `rhs`;())
  if NimMinor <= 17:
    for i in 0..<cnt: result[0][1].add(quote do:`t`[`i`])
  else:
    for i in 0..<cnt: result[1].add(quote do:`t`[`i`])

template input(T: typedesc, cnt: Natural = 1): untyped =
  let line = stdin.readLine.split(" ")
  when T is int:         line.map(parseInt).unpack(cnt)
  elif T is float:       line.map(parseFloat).unpack(cnt)
  elif T is string:      line.unpack(cnt)
  elif T is char:        line.mapIt(it[0]).unpack(cnt)
  elif T is seq[int]:    line.map(parseint)
  elif T is seq[float]:  line.map(parseFloat)
  elif T is seq[string]: line
  elif T is seq[char]:   line.mapIt(it[0])

# proc `%=`(n: var int, m: int)  = n = n mod m
# proc `//=`(n: var int, m: int) = n = n div m
# proc `<<=`(n: var int, m: int) = n = n shl m
# proc `>>=`(n: var int, m: int) = n = n shr m
# proc `<?=`(n: var int, m: int) = n = min(n, m)
# proc `>?=`(n: var int, m: int) = n = max(n, m)

proc upperBound[T, K](a: openArray[T], key: K, cmp: proc(x: T, k: K): int): int =
  result = a.low
  var count = a.high - a.low + 1
  var step, pos: int
  while count != 0:
    step = count shr 1
    pos = result + step
    if cmp(a[pos], key) <= 0:
      result = pos + 1
      count -= step + 1
    else:
      count = step

proc upperBound[T](a: openArray[T], key: T): int = upperBound(a, key, cmp[T])

# -------------------------------------------------- #

var N = input(int)
var X = @[0] & input(seq[int])
var L = input(int)

# R[k][i]: 2^k 日以内に i 件目から辿り着ける最も右のホテル
var R = newseqwith(21, newseq[int](N + 1))
for i in countup(1, N):
  R[0][i] = X.upperBound(X[i] + L) - 1
for k in countup(1, 20):
  for i in countup(1, N):
    R[k][i] = R[k - 1][R[k - 1][i]]

var Q = input(int)
for query in countup(1, Q):
  var (a, b) = input(int, 2)
  if a > b: swap(a, b)
  var res = 0
  for k in countdown(20, 0):
    if R[k][a] <= b:
      a = R[k][a]
      res += 2 ^ k
    if a == b:
      break
  echo res