def bfs(e,s,d,c,c_lat,d_max)
# init
queue = []
if(d <= d_max[s])
return
end
if(c_lat[s] == 0)
c_lat[s] = c
end
e[s].each{|nxtv|
queue.push([nxtv,s,d-1,c])
}
while(!queue.empty?)
# p queue
curv,curp,curd,c = queue.shift
if(curd <= d_max[curv])
next
end
if(c_lat[curv] == 0)
c_lat[curv] = c
end
if(d > 0)
e[curv].each{|nxtv|
queue.push([nxtv,curv,curd-1,c]) if curp != nxtv
}
end
end
end
N,M=gets.chomp.split(' ').map{|n| n.to_i}
# 0 indexed
E = Array.new(N){[]}
1.upto(M){
p=gets.chomp.split(' ').map{|n| n.to_i-1}
E[p[0]].push(p[1])
E[p[1]].push(p[0])
}
# p E
C_LAT = Array.new(N) { |i| 0 }
D_MAX = Array.new(N) { |i| -1 }
Q,_=gets.chomp.split(' ').map{|n| n.to_i}
query = []
for i in 0..(Q-1)
v,d,c = gets.chomp.split(' ').map{|n| n.to_i}
v -= 1
query << [v,d,c]
end
# p query
(Q-1).downto(0){|i|
v,d,c = query[i]
bfs(E,v,d,c,C_LAT,D_MAX)
}
for i in 0..(N-1)
puts C_LAT[i]
end