// Slower C++ solution:
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>

#include <sstream>

#include <iomanip>

#include <cstdio>

#include <cstdlib>

#include <cmath>

#include <cctype>

#include <cstring>

#include <vector>

#include <list>

#include <queue>

#include <deque>

#include <stack>

#include <map>

#include <set>

#include <algorithm>

#include <iterator>

#include <bitset>

#include <ctime>

#include<complex>

using namespace std;



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

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

#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)

#define FILL(a,value) memset(a, value, sizeof(a))



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

#define ALL(a) a.begin(), a.end()

#define PB push_back

#define MP make_pair



typedef long long LL;

typedef vector<int> VI;

typedef pair<int, int> PII;



const double PI = acos(-1.0);

const int INF = 1000 * 1000 * 1000 + 7;

const LL LINF = INF * (LL)INF;



const int MAX = 1000 * 100 + 47;



struct Item

{

	int v, d, c;

};



Item Q[MAX];

vector<int> g[MAX];

int U[MAX];

int D[MAX];

int C[MAX];

int iter;



void dfs(int v, int d, int curD, int color)

{

	if (d > curD) return;

	if (curD - d <= D[v]) return;

	D[v] = curD - d;

	if (C[v] == 0) C[v] = color;

	FOR(i, 0, SZ(g[v]))

	{

		int to = g[v][i];

		dfs(to, d + 1, curD, color);

	}

}



int main()

{

	//freopen("in.txt", "r", stdin);

	//freopen("out.txt", "w", stdout);

	//ios::sync_with_stdio(false); cin.tie(0);

	int n, m;

	cin >> n >> m;

	FOR(i, 0, m)

	{

		int a, b;

		cin >> a >> b;

		a--;

		b--;

		g[a].push_back(b);

		g[b].push_back(a);

	}



	int q;

	cin >> q;

	FOR(i, 0, q)

	{

		cin >> Q[i].v >> Q[i].d >> Q[i].c;

		Q[i].v--;

	}



	reverse(Q, Q + q);

	FILL(D, -1);

	FOR(i, 0, q)

	{

		dfs(Q[i].v, 0, Q[i].d, Q[i].c);

	}



	FOR(i, 0, n)

	{

		//cout << i + 1 << ": " << C[i] << "\n";

		cout << C[i] << "\n";



	}

}

// Faster C++ solution for the same problem (measured speedup: 3.9909115594311153x):
#include<bits/stdc++.h>

#define rint register int

using namespace std;

int read(){

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

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

    while(c>='0'&&c<='9')s=(s<<1)+(s<<3)+(c^48),c=getchar();

    return f?s:-s;

}

int n,m,Q,s[100010],mmp[100010],cl[100010];

int col[100010],vis[100010][11],hxcAK[100010];

int tot,head[100010],ver[200010],nxt[200010];

void add(int x,int y){

    nxt[++tot]=head[x]; ver[tot]=y;

    head[x]=tot;

}

void dfs(int x,int dis,int cr){

	if(!hxcAK[x]) col[x]=cr,hxcAK[x]=1;

	vis[x][dis]=1;

	if(dis==0) return;

	for(rint i=head[x];i;i=nxt[i]){

		int y=ver[i];

		if(vis[y][dis-1]) continue;

		vis[y][dis-1]=1;

		dfs(y,dis-1,cr);

	}

}

int main(){

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

    for(rint i=1,x,y;i<=m;++i){

        x=read(); y=read();

        add(x,y); add(y,x);

    }

    Q=read();

    for(rint i=1;i<=Q;++i)

        s[i]=read(),mmp[i]=read(),cl[i]=read();

    for(rint i=Q;i;--i) dfs(s[i],mmp[i],cl[i]);

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

    return 0;

}

/*

14 10

1 4

5 7

7 11

4 10

14 7

14 3

6 14

8 11

5 13

8 3

8

8 6 2

9 7 85

6 9 3

6 7 5

10 3 1

12 9 4

9 6 6

8 2 3



*/