#include <bits/stdc++.h>
using namespace std;

const int N = 1e5 + 5;
vector<int> adj[N];
int ans[N];
int vis[N][15];
int v[N], d[N], c[N];
int n, m, q;

void dfs(int u, int d, int c) {
	if (vis[u][d])
		return;
	if (!ans[u])
		ans[u] = c;
	vis[u][d]++;
	if (!d)
		return;
	for (int nxt : adj[u]) {
		dfs(nxt, d - 1, c);
	}
}

int main() {

	int a, b;
	scanf("%d%d", &n, &m);
	for (int i = 0; i < m; i++) {
		scanf("%d%d", &a, &b);
		adj[a].push_back(b);
		adj[b].push_back(a);
	}

	scanf("%d", &q);
	for (int i = 0; i < q; i++) {
		scanf("%d%d%d", &v[i], &d[i], &c[i]);
	}

	for (int i = q - 1; ~i; i--) {
		dfs(v[i], d[i], c[i]);
	}

	for (int i = 1; i <= n; i++) {
		printf("%d\n", ans[i]);
	}

	return 0;
}
