let nil = -1

type node = { value : int; left : int; right : int }

let make_node () = { value = nil; left = nil; right = nil }

let split_on_char sep s =
  let open String in
  let r = ref [] in
  let j = ref (length s) in
  for i = length s - 1 downto 0 do
    if get s i = sep then begin
      r := sub s (i + 1) (!j - i - 1) :: !r;
      j := i
    end
  done;
  sub s 0 !j :: !r

let sort_range (a : (int * int * int) array) first last cmp =
  let swap i j = let tmp = a.(i) in a.(i) <- a.(j); a.(j) <- tmp in
  let partition p r =
    let i = ref p in
    for j = p to r - 1 do
      if cmp a.(j) a.(r) <= 0 then (swap !i j; incr i)
    done;
    swap !i r;
    !i in
  let rec doit p r =
    if p >= r then () else
    let q = partition p r in
    doit p (q - 1);
    doit (q + 1) r in
  doit first (last - 1)

let make_kd_tree p t n =
  let rec doit l r d =
    if l >= r then nil
    else begin
      if d mod 2 = 0 then sort_range p l r (fun (_, ax, _) (_, bx, _) -> ax - bx)
      else sort_range p l r (fun (_, _, ay) (_, _, by) -> ay - by);
      let m = (l + r) / 2 in
      t.(m) <- {value = m; left = doit l m (d + 1); right = doit (m + 1) r (d + 1)};
      m
    end in
  let root = doit 0 n 0 in
  (root, p, t)

let ans = ref []

let find (p : (int * int * int) array) t root sx tx sy ty =
  let rec doit i d =
    let (id, x, y) = p.(t.(i).value) in
    if sx <= x && x <= tx && sy <= y && y <= ty then ans := id :: !ans;
    if d mod 2 = 0 then begin
      if t.(i).left != nil && sx <= x then doit t.(i).left (d + 1);
      if t.(i).right != nil && x <= tx then doit t.(i).right (d + 1);
    end else begin
      if t.(i).left != nil && sy <= y then doit t.(i).left (d + 1);
      if t.(i).right != nil && y <= ty then doit t.(i).right (d + 1);
    end in
  doit root 0

let () =
  let n = read_int () in
  let p =
    Array.init n (fun i ->
      match read_line () |> split_on_char ' ' |> List.map int_of_string with
      | [x; y] -> (i, x, y)
      | _ -> assert false) in
  let t = Array.make n (make_node ()) in
  let (root, p, t) = make_kd_tree p t n in
  let q = read_int () in
  for _ = 0 to q - 1 do
    match read_line () |> split_on_char ' ' |> List.map int_of_string with
    | [sx; tx; sy; ty] ->
      find p t root sx tx sy ty;
      List.iter (fun e -> Printf.printf "%d\n" e) (List.sort (-) !ans);
      Printf.printf "\n";
      ans := []
    | _ -> assert false
  done