#include<bits/stdc++.h>
using namespace std;
struct E{int v,next;}g[200005];
int n,m,q,h[100005],v[100005],d[100005],c[100005],color[100005],t,dis[100005];
inline int read(){
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+ch-'0';ch=getchar();}
    return x*f;
}
void ins(int u,int v){g[++t].v=v,g[t].next=h[u],h[u]=t;}
void dfs(int v,int d,int c){
	if(d==0||dis[v]>=d) return;
	dis[v]=d; if(color[v]==0) color[v]=c;
	for(int i=h[v];i;i=g[i].next) dfs(g[i].v,d-1,c);
}
int main(){
	n=read(),m=read();
	for(int i=1;i<=m;++i){
		int u,v;
		u=read(),v=read();
		ins(u,v),ins(v,u);
	}
	q=read();
	for(int i=1;i<=q;++i) v[i]=read(),d[i]=read(),c[i]=read();
	for(int i=q;i>=1;--i) dfs(v[i],d[i]+1,c[i]);
	for(int i=1;i<=n;++i) printf("%d\n",color[i]);
}