let () = Scanf.scanf "%d %d\n" @@ fun n m ->
  let es = Array.make n [] in
  for i = 0 to m - 1 do
    Scanf.scanf "%d %d\n" @@ fun a b ->
      es.(a - 1) <- b - 1 :: es.(a - 1);
      es.(b - 1) <- a - 1 :: es.(b - 1)
  done;
  let rs = Array.make n min_int in
  let cs = Array.make n 0 in
  Scanf.scanf "%d\n" @@ fun q ->
    let rec dfs d c v =
      if rs.(v) < d && 0 <= d then begin
        rs.(v) <- d;
        if cs.(v) = 0 then
          cs.(v) <- c;
        List.iter (dfs (d - 1) c) es.(v)
      end in
    let vdcs = Array.init q @@ fun _ -> Scanf.scanf "%d %d %d\n" @@ fun v d c -> v, d, c in
    List.iter (fun (v, d, c) -> dfs d c (v - 1)) (List.rev (Array.to_list vdcs));
    Array.iter (Printf.printf "%d\n") cs

