#include <bits/stdc++.h>

using namespace std;

#define rep(i, a, b)	for (int i(a); i <= (b); ++i)
#define dec(i, a, b)	for (int i(a); i >= (b); --i)
#define MP		make_pair
#define fi		first
#define se		second


typedef long long LL;

const int N = 1e5 + 10;

int f[N][11], ret[N];
int a[N], b[N], c[N];
int n, m, k;

vector <int> v[N];

void solve(int x, int y, int z){
	if (~f[x][y]) return;
	if (!ret[x]) ret[x] = z;
	if (y <= 0) return;
	for (auto u : v[x]){
		solve(u, y - 1, z);
	}
	f[x][y] = 1;
}

int main(){

	scanf("%d%d", &n, &m);
	rep(i, 1, m){
		int x, y;
		scanf("%d%d", &x, &y);
		v[x].push_back(y);
		v[y].push_back(x);
	}

	scanf("%d", &k);
	rep(i, 1, k){
		scanf("%d%d%d", a + i, b + i, c + i);
	}

	memset(f, -1, sizeof f);
	dec(i, k, 1) solve(a[i], b[i], c[i]);
	rep(i, 1, n) printf("%d\n", ret[i]);
	return 0;
}


