// 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: 1.9482438610886543x):
#include<stdio.h>

#include<string.h>

#include<iostream>

#include<algorithm>

#include<queue>

using namespace std;

const int maxn=(int)1e5+10;

int read()

{

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

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

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

    return x*f;

}

struct node{

	int to,nxt;

}ed[maxn<<1];

int head[maxn],cnt;

void addedge(int u,int v){

	ed[cnt].to=v;

	ed[cnt].nxt=head[u];

	head[u]=cnt++;

}

int st[maxn],d[maxn],c[maxn],mark[maxn],dis[maxn],col[maxn];

vector<int>vx;

int main()

{

	int n,m;

	memset(head,-1,sizeof(head));

	memset(mark,-1,sizeof(mark));

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

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

		int u,v;

		u=read(),v=read();

		addedge(u,v);

		addedge(v,u);

	}

	int q;

	scanf("%d",&q);

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

		st[i]=read();d[i]=read();c[i]=read();

	}

	for(int i=q;i>=1;i--){

		if(d[i]<=mark[st[i]])continue;

		queue<int>q;

		q.push(st[i]);

		while(!q.empty()){

			int u=q.front();q.pop();

			if(dis[u]+mark[u]>=d[i])continue;

			if(col[u]==0)col[u]=c[i];	

			mark[u]=d[i]-dis[u];

			for(int j=head[u];~j;j=ed[j].nxt){

				int v=ed[j].to;

				if(dis[v]==0&&v!=st[i]&&dis[u]<d[i]){

					dis[v]=dis[u]+1;

					vx.push_back(v);

					q.push(v);

				}

			}

		}

		for(int j=0;j<vx.size();j++)dis[vx[j]]=0;

		vx.clear();

	}

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

	return 0;

}