
let md (a, b) (c, d) = abs (a - c) + abs (b - d)

let mind cps (a, b) = snd @@ List.hd @@ List.sort (fun ((c1, d1), i1) ((c2, d2), i2) ->
                                                   let d1 = md (a, b) (c1, d1) in
                                                   let d2 = md (a, b) (c2, d2) in
                                                   if d1 = d2 then compare i1 i2 else compare d1 d2
                                                  ) cps
                                           
let _ =
  let n, m = Scanf.scanf "%d %d\n" (fun x y -> (x, y)) in
  let rec read n = if n <= 0 then []
                   else let x = Scanf.scanf "%d %d\n" (fun x y -> (x, y))
                        in x :: read (n - 1) in
  let sts = read n in
  let cps = List.mapi (fun i p -> (p, i+1)) (read m) in
  List.iter (fun x -> Printf.printf "%d\n" x) (List.map (mind cps) sts)
