// Original C++ solution (slower):
#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？

*/


// Optimized solution to the same problem (faster):
//#pragma GCC optimize(2)

//#pragma GCC optimize(3)

#include <bits/stdc++.h>

#define N 100005

#define int long long

//#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<22,stdin),p1 == p2)?EOF:*p1++)

using namespace std ;

//char buf[(1 << 22)] , *p1 = buf , *p2 = buf ;

inline int read ()

{

    char c = getchar () ; int x = 0 , f = 1 ;

    while (c < '0' || c > '9') { if (c == '-') f = -1 ; c = getchar () ; }

    while (c >= '0' && c <= '9'){ x = x * 10 + c - '0' ; c = getchar () ; }

    return x * f ;

}

int n , m , ver[N << 1] , nxt[N << 1] , hed[N] , tot , ans[N] , Dis[N] ;

struct as {

	int v , d , c ;

} a[N] ;

void add (int x , int y) { ver[++ tot] = y ; nxt[tot] = hed[x] ; hed[x] = tot ; }

void dfs (int x , int col , int dis)

{

	if (! ans[x]) ans[x] = col ;

	if (! dis || Dis[x] >= dis) return ;

	Dis[x] = dis ;

	for (int i = hed[x] ; i ; i = nxt[i])

	{

		int y = ver[i] ;

		dfs (y , col , dis - 1) ;

	}

}

signed main ()

{

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

	for (int i = 1 , u , v ; i <= m ; u = read () , v = read () , add (u , v) , add (v , u) , i ++) ;

	int q = read () ;

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

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

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

}

/*

7 7

1 2

1 3

1 4

4 5	

5 6

5 7

2 3

2

6 1 1

1 2 2

*/

// Fastest known solution for this problem: