Scanf.scanf "%d %d" (fun n m ->
    let nei = Array.make n [] in
    for i = 1 to m do
        Scanf.scanf " %d %d" (fun a b ->
            let a = a - 1 in
            let b = b - 1 in
            nei.(a) <- b :: nei.(a);
            nei.(b) <- a :: nei.(b);
        )
    done;

    Scanf.scanf " %d" (fun q ->
        let vdc = Array.init q (fun _ -> Scanf.scanf " %d %d %d" (fun v d c -> v - 1, d, c)) in
        let col = Array.make_matrix n 11 0 in
        for i = q - 1 downto 0 do
            let rec fill v d c =
                if col.(v).(d) = 0 then (
                    col.(v).(d) <- c;
                    if d > 0 then (
                        fill v (d - 1) c;
                        List.iter (fun next -> fill next (d - 1) c) nei.(v)
                    )
                )
            in
            let v, d, c = vdc.(i) in
            fill v d c
        done;
        Array.iter (fun a -> Printf.printf "%d\n" a.(0)) col
    )
)