let nil = -1

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

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

let split str delim =
  let open String in
  let rec doit s acc =
    match
      try Some (rindex s delim) with _ -> None
    with
    | None -> s :: acc
    | Some i -> doit (sub s 0 i) (sub s (i + 1) (length s - i - 1) :: acc) in
  doit str []

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 rec exchange = function
      | (i, j) when j = r -> swap i r; i
      | (i, j) when cmp a.(j) a.(r) <= 0 -> swap i j; exchange (i + 1, j + 1)
      | (i, j) -> exchange (i, j + 1) in
    exchange (p, p) in
  let rec doit p r =
    if p < r then begin
      let q = partition p r in
      doit p (q - 1);
      doit q r
    end in
  doit first (last - 1)

let make_kd_tree p t n =
  let num = ref 0 in
  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
      let i = !num in
      incr num;
      let il = doit l m (d + 1) in
      let ir = doit (m + 1) r (d + 1) in
      t.(i) <- { value = m; left = il; right = ir };
      i
    end in
  let _ = doit 0 n 0 in
  (p, t)

let find (p : (int * int * int) array) t (sx, sy) (tx, ty) =
  let acc = ref [] in
  let rec doit i d =
    let (id, x, y) = p.(t.(i).value) in
    if sx <= x && x <= tx && sy <= y && y <= ty then acc := id :: !acc;
    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 0 0;
  acc

let () =
  let n = read_int () in
  let p = Array.init n (fun i ->
    match List.map int_of_string (split (read_line ()) ' ') with
    | [x; y] -> (i, x, y)
    | _ -> exit 1) in
  let t = Array.make n (make_node ()) in
  let (p, t) = make_kd_tree p t n in
  let q = read_int () in
  let rec doit i =
    if i < q then
      begin match List.map int_of_string (split (read_line ()) ' ') with
      | [sx; tx; sy; ty] ->
        let z = find p t (sx, sy) (tx, ty) in
        List.iter (fun e -> Printf.printf "%d\n" e) (List.sort (-) !z);
        print_newline ();
        doit (i + 1)
      | _ -> exit 1
      end in
  doit 0