integer N,M
integer,allocatable::a(:),b(:)
integer Q,v,d
integer,allocatable::c(:),dp(:,:)
read*,N,M
allocate(a(M),B(M))
do i=1,M
  read*,a(i),b(i)
end do
read*,Q
allocate(c(Q))
allocate(DP(0:11,N))
DP=0
do i=1,Q
  read*,v,d,C(i)
  DP(D,V)=i
end do
do i=10,0,-1
  do j=1,N
    DP(i,j)=max(DP(i,j),DP(i+1,j))
  end do
  do j=1,M
    DP(i,a(j)) = max( DP(i,a(j)), DP(i+1,b(j)) )
	DP(i,b(j)) = max( DP(i,b(j)), DP(i+1,a(j)) )
  end do
end do
do i=1,N
  print"(i0)",C(DP(0,i))
end do
end