#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;

bool m[100000][11];
int col[100000];
vector<int>E[100000];
int v[100000], d[100000], c[100000];
void rec(int v, int d, int c) {
	if (m[v][d])return;
	m[v][d] = 1;
	if (col[v] == 0)col[v] = c;
	if (!d)return;
	rec(v, d - 1, c);
	for (int u : E[v])rec(u, d - 1, c);
}
int main() {
	int n, m; scanf("%d%d", &n, &m);
	rep(i, m) {
		int a, b; scanf("%d%d", &a, &b); a--; b--;
		E[a].push_back(b); E[b].push_back(a);
	}
	int q; scanf("%d", &q);
	rep(i, q) {
		scanf("%d%d%d", &v[i], &d[i], &c[i]); v[i]--;
	}
	for (int i = q - 1; i >= 0; i--)rec(v[i], d[i], c[i]);
	rep(i, n)printf("%d\n", col[i]);
}