Scanf.scanf "%d %d" (fun n m ->
    let ab = Array.init n (fun _ -> Scanf.scanf " %d %d" (fun a b -> a, b)) in
    let cd = Array.init m (fun _ -> Scanf.scanf " %d %d" (fun a b -> a, b)) in
    for i = 0 to n - 1 do
        let x, y = ab.(i) in
        let rec loop j mip mid =
            if j = m then mip else
            let w, h = cd.(j) in
            let d = abs (x - w) + abs (y - h) in
            if d < mid then loop (j + 1) (j + 1) d
                       else loop (j + 1) mip mid
        in
        Printf.printf "%d\n" @@ loop 0 0 max_int
    done
)