#include <bits/stdc++.h>
#define ll long long

using namespace std;
const int MAXN = 200005;
const int MOD = 1000000007;

vector<int> g[MAXN];
int c[MAXN],mx[MAXN],v[MAXN],d[MAXN],cc[MAXN],cur;

void dfs(int a){
	if(c[a] == 0) c[a] = cc[cur];
	for(int i:g[a]) if(mx[i] < mx[a]-1){
		mx[i] = mx[a]-1;
		dfs(i);
	}
}

int main(){
	ios_base::sync_with_stdio(false); cin.tie(0);
	int n,m; cin >> n >> m;
	memset(mx,-1,sizeof mx);
	for(int i=0;i<m;i++){
		int a,b; cin >> a >> b;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	int q; cin >> q; 
	for(int i=0;i<q;i++) cin >> v[i] >> d[i] >> cc[i];
	for(int i=q-1;i>=0;i--){
		if(mx[v[i]] < d[i]){
			mx[v[i]] = d[i];
			cur = i;
			dfs(v[i]);
		}
	}
	for(int i=1;i<=n;i++) cout << c[i] << '\n';
	return 0;
}
