#include<cstdio>
#include<cstring>
const int maxn = 100500;
int head[maxn], d[maxn], v[maxn], c[maxn], pri[maxn], f[maxn];
int n, m, q, x, y, tot;
struct Edge {
	int u, v, next;
} e[maxn*2];
void add_edge(int u, int v) {
	 e[++tot] = (Edge){u, v, head[u]};
	 head[u] = tot;
}
void dfs(int u, int dis, int col) {
	if(dis <= f[u]) return;
	f[u] = dis;
	if(dis <= 0) return;  
	if(!pri[u]) pri[u] = col;
	for(int i = head[u]; i; i = e[i].next) {
		int v = e[i].v;
		dfs(v, dis-1, col);
	}
}
int main() {
	scanf("%d%d", &n, &m);
	for(int i = 1; i <= m; i++) {
		scanf("%d%d", &x, &y);
		add_edge(x, y);
		add_edge(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 >= 1; i--) dfs(v[i], d[i]+1, c[i]);
	for(int i = 1; i <= n; i++) printf("%d\n", pri[i]);
	return 0;
} 