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 qv, qd, qc = {}, {}, {}
for iq = 1, q do
  qv[iq], qd[iq], qc[iq] = io.read("*n", "*n", "*n")
end
local tv, td, tc = {}, {}, {}
for iq = q, 1, -1 do
  local taskpos = 1
  tv[1], td[1], tc[1] = qv[iq], qd[iq], qc[iq]
  while 0 < taskpos do
    local src, d, c = tv[taskpos], td[taskpos], tc[taskpos]
    taskpos = taskpos - 1
    if searched_len[src] < d then
      searched_len[src] = d
    end
    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
          taskpos = taskpos + 1
          tv[taskpos] = dst
          td[taskpos] = d - 1
          tc[taskpos] = c
        end
      end
    end
  end
end
for i = 1, n do
  print(color[i])
end
