// Slower C++ solution:
#include <map>

#include <set>

#include <cmath>

#include <ctime>

#include <queue>

#include <stack>

#include <vector>

#include <bitset>

#include <cstdio>

#include <cctype>

#include <string>

#include <cstring>

#include <cassert>

#include <climits>

#include <cstdlib>

#include <iostream>

#include <algorithm>

#include <functional>

using namespace std ;



#define rep(i, a, b) for (int (i) = (a); (i) <= (b); (i)++)

#define Rep(i, a, b) for (int (i) = (a) - 1; (i) < (b); (i)++)

#define REP(i, a, b) for (int (i) = (a); (i) >= (b); (i)--)

#define clr(a) memset(a, 0, sizeof(a))

#define Sort(a, len, cmp) sort(a + 1, a + len + 1, cmp)

#define ass(a, sum) memset(a, sum, sizeof(a))



#define ls ((rt) << 1)

#define rs ((rt) << 1 | 1)

#define lowbit(x) (x & -x)

#define mp make_pair

#define pb push_back

#define fi first

#define se second

#define endl '\n'

#define ENDL cout << endl

#define SZ(x) ((int)x.size())



typedef long long ll ;

typedef unsigned long long ull ;

typedef vector <int> vi ;

typedef pair <int, int> pii ;

typedef pair <ll, ll> pll ;

typedef map <int, int> mii ;

typedef map <string, int> msi ;

typedef map <ll, ll> mll ;



const int N = 100010 ;

const double eps = 1e-8 ;

const int iinf = INT_MAX ;

const ll linf = 2e18 ;

const double dinf = 1e30 ;

const int MOD = 1000000007 ;



inline int read(){

    int X = 0, w = 0 ;

	char ch = 0 ;

    while (!isdigit(ch)) { w |= ch == '-' ; ch = getchar() ; }

    while (isdigit(ch)) X = (X << 3) + (X << 1) + (ch ^ 48), ch = getchar() ;

    return w ? - X : X ;

}



void write(int x){

     if (x < 0) putchar('-'), x = - x ;

     if (x > 9) write(x / 10) ;

     putchar(x % 10 + '0') ;

}



void print(int x) {

	cout << x << endl ;

	exit(0) ;

}



void PRINT(string x) {

	cout << x << endl ;

	exit(0) ;

}



void douout(double x){

	 printf("%lf\n", x + 0.0000000001) ;

}



int n, m, Q ;

int ans[N], mx[N], a[N], b[N], c[N] ;

vector <int> e[N] ;



void dfs(int now) {

	if (!ans[now]) ans[now] = c[Q] ;

	for (int i = 0; i < SZ(e[now]); i++) {

		int to = e[now][i] ;

		if (mx[now] - 1 > mx[to]) mx[to] = mx[now] - 1, dfs(to) ;

	}

}



signed main(){

	ass(mx, -1) ;

	scanf("%d%d", &n, &m) ;

	for (int i = 1; i <= m; i++) {

		int a, b ;

		scanf("%d%d", &a, &b) ;

		e[a].pb(b) ;

		e[b].pb(a) ;

	}

	scanf("%d", &Q) ;

	for (int i = 1; i <= Q; i++) scanf("%d%d%d", &a[i], &b[i], &c[i]) ;

	for (; Q; Q--)

		if (b[Q] > mx[a[Q]]) mx[a[Q]] = b[Q], dfs(a[Q]) ;

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

}



/*

写代码时请注意：

	1.是否要开Long Long？数组边界处理好了么？

	2.实数精度有没有处理？

	3.特殊情况处理好了么？

	4.做一些总比不做好。

思考提醒：

	1.最大值和最小值问题可不可以用二分答案？

	2.有没有贪心策略？否则能不能dp？

*/


// Faster C++ solution for the same problem (measured speedup: 3.9726872843173973x):
#include<bits/stdc++.h>//这题是倒着染色吧

using namespace std;



const int N = 1e5 + 10;

int n, m;

struct edge { int y, nxt; } e[N << 2];

int lin[N], len;

int ans[N][20];

struct QUE { int v, d, c; } q[N];



inline int read() {

	int s = 0, f = 1;

	char ch;

	for(; ch < '0' || ch > '9'; ch = getchar())	if(ch == '-')	f = -1;

	for(; ch >= '0' && ch <= '9'; ch = getchar())	s = (s << 1) + (s << 3) + ch - '0';

	return s * f;

}



inline void insert(int xx, int yy) {

	e[++len] = (edge) { yy, lin[xx] };

	lin[xx] = len;

}



inline void dfs(int v, int d, int c) {

	if(d == -1)	return ;

	if(ans[v][d])	return ;//因为是倒着染，所以不用再染一遍

	ans[v][d] = c;

	for(int i = lin[v]; i; i = e[i].nxt)	dfs(e[i].y, d - 1, c);

}



int main() {

	n = read(), m = read();

	for(int i = 1; i <= m; ++i) {

		int x = read(), y = read();

		insert(x, y);

		insert(y, x);

	}

	for(int i = 1; i <= n; ++i)	insert(i, i);

	int Q = read();

	for(int i = 1; i <= Q; ++i)	q[i].v = read(), q[i].d = read(), q[i].c = read();

	for(int i = Q; i >= 1; --i)	dfs(q[i].v, q[i].d, q[i].c);

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

	return 0;

}

//感谢ZJH大佬提供思路