let rec loop x fn =
  match fn x with
  | `Break x -> x
  | `Continue x -> loop x fn

module List = struct
  include List
  let take n lst =
    loop (0, lst, []) begin fun (i, rest, r_acc) ->
      match i < n, rest with
      | true, []  | false, _ -> `Break (rev r_acc)
      | true, x :: rest -> `Continue (i + 1, rest, x :: r_acc) end
  let drop n lst =
    loop (0, lst) begin fun (i, rest) ->
      match i < n, rest with
      | true, _ :: rest -> `Continue (i + 1, rest)
      | true, []  | false, _ -> `Break rest end
end

let () =
  let open Scanf in
  let read_ints () = let open Buffer in
    let buf = create 10 in
    let add = add_bytes buf and get () = contents buf in
    loop () begin fun () ->
      try read_line () ^ " " |> add; `Continue ()
      with _ -> `Break (get ()) end
    |> Str.(split (regexp " ")) |> List.map int_of_string in

  let rest = read_ints () in
  let n :: rest = rest in
  let xs = List.take n rest in
  let l :: q :: qs = List.drop n rest in
  let qs =
    let qs = qs |> List.map (fun q -> q - 1) in
    loop (qs, []) begin fun (rest, r_acc) ->
      match rest with
      | x:: y:: rest -> `Continue (rest, (x, y):: r_acc)
      | []  | _:: [] -> `Break (List.rev r_acc) end in
  (* input stage is finally finished *)

  let xs = Array.of_list xs in
  let bisect fn_shift fn_idx = fun x -> 
    loop (0, n) begin fun (l, r) ->
      if r - l - 1 = 0 then `Break (fn_idx l r)
      else let m = (l + r) / 2 in
        match fn_shift x xs.(m) with
        | `Left -> `Continue (l, m)
        | `Right -> `Continue (m, r) end in
  let bisect_l = bisect
      (fun x m -> if x < m then `Left else `Right) (fun l r -> l)
  and bisect_r = bisect
      (fun x m -> if x > m then `Right else `Left) (fun l r -> r) in

  let solve (a, b) =
    let bisect, reached, next =
      if a < b
      then (bisect_l, (fun x -> b <= x), (fun x -> x + l))
      else (bisect_r, (fun x -> x <= b), (fun x -> x - l)) in
    loop (a, 0) begin fun (a, cnt) ->
      let x' = next xs.(a) in
      let a' = bisect x' in
      (* Printf.printf "(a=%d, x=%d), " (a' + 1) x'; *)
      if reached a' then `Break (cnt + 1)
      else `Continue (a', cnt + 1) end in

  let add, get = let open Buffer in
    let buf = create (q * 2) in
    let add = add_string buf and get () = contents buf in
    add, get in
  qs |> List.map begin fun q ->
    let open Printf in
    (* printf "q:(%d,%d)" (fst q) (snd q); flush_all (); *)
    add (sprintf "%d\n" (solve q));
  end |> ignore;
  Printf.printf "%s" (get ());
