#include <bits/stdc++.h>

int n, m, q;
std::vector<int> *g;
int *rem[11], *v, *d, *c;

int main() {
	scanf("%d%d", &n, &m);
	g = new std::vector<int>[n];
	for (int i = 0; i < 11; ++i) {
		rem[i] = new int[n];
		for (int j = 0; j < n; ++j) {
			rem[i][j] = 0;
		}
	}
	for (int i = 0; i < m; ++i) {
		int u, v;
		scanf("%d%d", &u, &v);
		g[--u].push_back(--v);
		g[v].push_back(u);
	}
	scanf("%d", &q);
	v = new int[q];
	d = new int[q];
	c = new int[q];
	for (int i = 0; i < q; ++i) {
		scanf("%d%d%d", v + i, d + i, c + i);
		rem[d[i]][--v[i]] = i + 1;
	}
	for (int i = 10; i; --i) {
		for (int u = 0; u < n; ++u) {
			for (int v: g[u]) {
				rem[i - 1][v] = std::max(rem[i - 1][v], rem[i][u]);
			}
		}
	}
	for (int u = 0; u < n; ++u) {
		int mx = 0;
		for (int d = 0; d < 11; ++d) {
			mx = std::max(mx, rem[d][u]);
		}
		printf("%d\n", mx ? c[mx - 1] : 0);
	}
	return 0;
}