type point = { id : int; x : int; y : int }

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

let nil = -1

let make_point () = { id = nil; x = nil; y = nil }
let make_node () = { value = nil; left = nil; right = nil }

let p = Array.make 500001 (make_point ())
let t = Array.make 500001 (make_node ())

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 generate_g n =
  let rec doit i acc =
    if i > n then acc
    else doit (3*i + 1) (i :: acc) in
  doit 1 []

let generate_g n =
  let rec doit i g acc =
    if g > n then acc
    else doit (i + 1) (int_of_float (4.**(float_of_int i) +. 3.*.2.**(float_of_int (i - 1)) +. 1.)) (g :: acc) in
  doit 1 1 []

let insertion_sort first last g cmp =
  let rec insert j v =
    if j < first || cmp p.(j) v <= 0 then p.(j+g) <- v
    else begin
      p.(j+g) <- p.(j);
      insert (j - g) v
    end in
  let rec doit i =
    if i < last then begin
      insert (i - g) p.(i);
      doit (i + 1)
    end in
  doit (g + first)

let shell_sort first last cmp =
  let rec doit = function
    | [] -> ()
    | hd :: tl ->
      insertion_sort first last hd cmp;
      doit tl in
  doit (generate_g (last - first))

let make_kd_tree n =
  let rec doit l r d =
    if l >= r then nil
    else begin
      if d mod 2 = 0 then shell_sort l r (fun a b -> a.x - b.x)
      else shell_sort l r (fun a b -> a.y - b.y);
      let m = (l + r) / 2 in
      let il = doit l m (d + 1) in
      let ir = doit (m + 1) r (d + 1) in
      t.(m) <- { value = m; left = il; right = ir };
      m
    end in
  doit 0 n 0

let (ans : int list ref) = ref []

let find root sx tx sy ty =
  let rec doit i d =
    let (id, x, y) = (p.(t.(i).value).id, p.(t.(i).value).x, p.(t.(i).value).y) 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 rec read i =
    if i < n then begin
      begin match List.map int_of_string (split (read_line ()) ' ') with
      | [x; y] -> p.(i) <- { id = i; x; y }
      | _ -> exit 1
      end;
      read (i + 1)
    end in
  read 0;
  let root = make_kd_tree 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] ->
        find root sx tx sy ty;
        List.iter (fun e -> Printf.printf "%d\n" e) (List.sort (-) !ans);
        print_string "\n";
        ans := [];
        doit (i + 1)
      | _ -> exit 1
      end in
  doit 0