// Slower C++ solution:
//#pragma GCC optimize("O3")

#include <bits/stdc++.h>



using namespace std;



typedef long long ll;



const int N = (int) 1e5 + 5;

const int mod = (int) 1e9 + 7;



vector<int> g[N];

int n, m, Q, ans[N], ds[N], u[N];

int q[N * 100], qd[N * 100], qb, qe, t = 1, f[N];



void paint (int c) {

        while (qb < qe) {

                int v = q[qb], d = qd[qb++];

                if (ans[v] != 0 && ds[v] >= d) {

                        continue;

                }

                if (!ans[v]) {

                        ans[v] = c; ds[v] = d;

                }else



                {

                        ds[v] = d;

                }

                if (d) {

                        for (int to : g[v]) {

                                if (u[to] != t) {

                                        u[to] = t;

                                        q[qe] = to;

                                        qd[qe++] = d - 1;

                                }

                        }

                }

        }

        qb = qe = 0; ++t;

}



int v[N], d[N], c[N];



inline void solve () {

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

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

                int x, y;

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

                g[x].emplace_back (y);

                g[y].emplace_back (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--) {

                q[qe] = v[i]; qd[qe++] = d[i];

                u[v[i]] = t;

                if (c[i] != c[i - 1]) {

                        paint (c[i]);

                }

        }

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

                printf ("%d\n", ans[i]);

        }

}



int tests = 1;



int main () {

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

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

//        scanf ("%d", &tests);

        while (tests--) {

                solve ();

        }

        return 0;

}


// Faster C++ solution for the same problem (measured speedup: 3.568950964691163x):
/*   三玖天下第一！！！  */

#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;

}