import sys
import bisect
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 i in range(n-1):
  x = bisect.bisect_right(a,a[i]+d)
  if x == i:
    continue
  graph[i+1] = x
group = [0]*(n+1)
row = [[]]
cnt = 0
stack = []
for i in range(1,n+1):
  if group[i] == 0:
    stack.append(i)
    cnt += 1
    row.append([])
    while stack:
      x = stack.pop()
      row[cnt].append(x)
      group[x] = cnt
      if x != n:
        stack.append(graph[x])
q = int(input())
for _ in range(q):
  l,r = map(int,input().split())
  if l>r:
    l,r = r,l
  x = group[l]
  yl = bisect.bisect_left(row[x],l)
  yr = bisect.bisect_left(row[x],r)
  print(yr-yl)