fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());
    let n: usize = sc.read();
    let x: Vec<u64> = sc.vec(n);
    let l: u64 = sc.read();

    let x_max = x[n - 1];
    let mut inv_x = x.iter().map(|&x| x_max - x).collect::<Vec<_>>();
    inv_x.reverse();

    let q: usize = sc.read();
    let map = calc_map(x, l);
    let inv_map = calc_map(inv_x, l);
    for _ in 0..q {
        let a: usize = sc.read();
        let b: usize = sc.read();
        if a < b {
            let (a, b) = (a - 1, b - 1);

            let mut ok = 1 << 60;
            let mut ng = 0;
            while ok - ng > 1 {
                let cost = (ok + ng) / 2;
                if can_go(&map, a, b, cost) {
                    ok = cost;
                } else {
                    ng = cost;
                }
            }
            sc.write(format!("{}\n", ok));
        } else {
            let (a, b) = (n - a, n - b);

            let mut ok = 1 << 60;
            let mut ng = 0;
            while ok - ng > 1 {
                let cost = (ok + ng) / 2;
                if can_go(&inv_map, a, b, cost) {
                    ok = cost;
                } else {
                    ng = cost;
                }
            }
            sc.write(format!("{}\n", ok));
        }
    }
}

fn can_go(map: &Vec<Vec<usize>>, a: usize, b: usize, cost: u64) -> bool {
    let mut cur = a;
    for i in 0..60 {
        if (1 << i) & cost != 0 {
            cur = map[i][cur] - 1;
        }
    }
    cur >= b
}

fn calc_map(x: Vec<u64>, l: u64) -> Vec<Vec<usize>> {
    let n = x.len();
    let mut upper = vec![0; n];
    let mut tail = 0;
    for from in 0..n {
        if tail < from {
            tail = from;
        }
        while tail < n && x[tail] - x[from] <= l {
            tail += 1;
        }
        upper[from] = tail;
    }

    let mut map = vec![upper];
    for i in 0..60 {
        let mut upper = vec![0; n];
        for from in 0..n {
            let hop = map[i][from] - 1;
            upper[from] = map[i][hop];
        }
        map.push(upper);
    }
    map
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> IO<R, W> {
        IO(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: std::ops::Deref<Target = str>>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 131836