// 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.9949038722589667x):
/*   三玖天下第一！！！  */

#include<bits/stdc++.h>

using namespace std;

const int maxn=1e5,maxd=10;

int n,m,Q,_39[maxn+5]={},lin[maxn+5]={},len=0;

bool vis[maxn+5][maxd+5]={};

struct edge{int y,next;}e[(maxn<<1)+5];

inline void insert(int xx,int yy){e[++len]={yy,lin[xx]};lin[xx]=len;}

inline int dread()

{

	int x=0;bool f=1;char ch=getchar();

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

	for(;ch>='0'&&ch<='9';ch=getchar())x=(x<<1)+(x<<3)+(ch^48);

	return f?x:-x;

}

struct operation

{

	int v,d,c;

	inline void read(){v=dread();d=dread();c=dread();}

}opt[maxn+5];

void color(int point,int dis,int c)

{

	if(vis[point][dis]) return;else for(int i=0;i<=dis;i++)vis[point][i]=1;

	if(!_39[point]) _39[point]=c;

	if(!dis) return;

	for(int i=lin[point];i;i=e[i].next) color(e[i].y,dis-1,c);

}

inline void Kaslana()

{

	n=dread();m=dread();

	for(int i=1,u,v;i<=m;i++) insert(u=dread(),v=dread()),insert(v,u);

	Q=dread();

	for(int i=1;i<=Q;i++) opt[i].read();

}

inline void Raiden()

{

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

}

inline void Zaychik()

{

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

}

int main()

{

    Kaslana(),Raiden(),Zaychik();return 0;

}