local n, m = io.read("*n", "*n")
local edge = {}
local color = {}
local searched_len = {}
for i = 1, n do
  edge[i] = {}
  color[i] = 0
  searched_len[i] = -1
end
for i = 1, m do
  local a, b = io.read("*n", "*n")
  table.insert(edge[a], b)
  table.insert(edge[b], a)
end
local q = io.read("*n")
local query = {}
for iq = 1, q do
  query[iq] = {io.read("*n", "*n", "*n")}
end
for iq = q, 1, -1 do
  local tasks = {{unpack(query[iq])}}
  while 0 < #tasks do
    local src, d, c = unpack(tasks[#tasks])
    if searched_len[src] < d then
      searched_len[src] = d
    end
    table.remove(tasks)
    if color[src] == 0 then
      color[src] = c
    end
    if 0 < d then
      for i = 1, #edge[src] do
        local dst = edge[src][i]
        if searched_len[dst] < d - 1 then
          table.insert(tasks, {dst, d - 1, c})
        end
      end
    end
  end
end
for i = 1, n do
  print(color[i])
end
