// 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.918315931506068x):
#include<bits/stdc++.h>

using namespace std;

const int Max=1e5;

int N,M,Q,Num=0,num=0,lin[Max+10]={},Col[Max+10]={},v[Max+10]={},d[Max+10]={},c[Max+10]={},q[Max+10]={},vis[Max+10][15]={};

struct kk{

	int Id,Next;

} e[Max*2+10]={};

inline void insert(int x,int y){

	e[++Num].Next=lin[x]; lin[x]=Num; e[Num].Id=y;

}

inline void dfs(int x,int Dep,int col){

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

	if(vis[x][Dep]||Dep<=0) return;

	for(int i=0;i<=Dep;i++) ++vis[x][i];

	for(int i=lin[x];i;i=e[i].Next)

	 dfs(e[i].Id,Dep-1,col);

}

int main(){

	scanf("%d%d",&N,&M);

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

		int x,y; scanf("%d%d",&x,&y);

		insert(x,y); insert(y,x);

	}

	scanf("%d",&Q);

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

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

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

	return 0;

}