#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 100500;
const int D = 12;

int dp[N][D];
int n, m, q;
vector <vector <int> > g;
int v[N], d[N], c[N];

void draw(int v, int d, int c)
{
	if (d == -1 || dp[v][d])
		return;

	dp[v][d] = c;


	for (int to : g[v])
		draw(to, d - 1, c);
}

int main()
{                                                     
	ios_base::sync_with_stdio(0);

	cin >> n >> m;

	g.resize(n);

	for (int i = 0; i < m; i++)
	{
		int a, b;
		cin >> a >> b;
		a--, b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}

	cin >> q;

	for (int i = q - 1; i >= 0; i--)
	{
		cin >> v[i] >> d[i] >> c[i];
		v[i]--;
	}

	for (int i = 0; i < q; i++)
	{
		for (int x = d[i]; x >= 0; x--)
			draw(v[i], x, c[i]);
	}

	for (int i = 0; i < n; i++)
		cout << dp[i][0] << '\n';

	return 0;
}

