#include <cstdio> 
#define For(x) for (int h=head[x],o=V[h]; h; o=V[h=to[h]])
#define add(u,v) (to[++num]=head[u],head[u]=num,V[num]=v)
int num,head[2005],to[4005],V[4005];
int Q,n,m,v[2005],d[2005],c[2005],cl[2005],rg[2005];

void dfs(int x,int ran,int col){
	if (rg[x]>=ran || ran<=0) return;
	rg[x]=ran;
	cl[x]=col;
	For(x) dfs(o,ran-1,col);
}

int main(){
	scanf("%d%d",&n,&m);
	for (int i=1,x,y; i<=m; i++){
		scanf("%d%d",&x,&y);
		add(x,y);
		add(y,x);
	}
	scanf("%d",&Q);
	for (int i=1; i<=Q; i++) scanf("%d%d%d",&v[i],&d[i],&c[i]);	
	for (int i=Q; i; i--) dfs(v[i],d[i]+1,c[i]);
	for (int i=1; i<=n; i++) printf("%d\n",cl[i]);
}

//http://agc012.contest.atcoder.jp/tasks/agc012_b