// Slower C++ solution:
#include <vector>

#include <list>

#include <map>

#include <set>

#include <deque>

#include <stack>

#include <bitset>

#include <algorithm>

#include <functional>

#include <numeric>

#include <utility>

#include <sstream>

#include <iostream>

#include <iomanip>

#include <cstdio>

#include <cmath>

#include <cstdlib>

#include <ctime>

#include <memory.h>

#include <queue>



#define fr first

#define sc second

#define mk make_pair



using namespace std;



int n, m, color[100001], t[100001], dis[100001];

bool u[100001];

vector<int> vec[100001];

pair<int, int> ar[100001];



int main()

{

    cin >> n >> m;

    for(int i = 0; i < m; i++)

    {

        int a, b;

        scanf("%d%d", &a, &b);

        vec[a].push_back(b);

        vec[b].push_back(a);

    }



    int q;

    cin >> q;

    for(int i = 0; i < q; i++)

        scanf("%d%d%d", &ar[i].fr, &ar[i].sc, &t[i]);



    int v, d, col;

    queue <int> a, b, c;

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

    {

        a.push(ar[i].fr);

        u[ar[i].fr] = 1;

        b.push(ar[i].sc);

        c.push(t[i]);

        while(!a.empty())

        {

            v = a.front(), d = b.front(), col = c.front();

           // cout << v << " " << d << " " << col << endl;

            u[v] = 0;

            a.pop();

            b.pop();

            c.pop();

            if(color[v] == 0 || dis[v] < d)

            {

                if(color[v] == 0)

                {

                    color[v] = col;

                    dis[v] = d;

                }else

                {

                    dis[v] = d;

                }

                if(d > 0)

                for(int i = 0; i < vec[v].size(); i++)

                {

                    if(color[vec[v][i]] == 0 || dis[vec[v][i]] < d - 1 && u[vec[v][i]] == 0)

                    {

                        u[vec[v][i]] = 1;

                        a.push(vec[v][i]);

                        b.push(d - 1);

                        c.push(col);

                    }

                }

            }

        }

    }



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

    {

        //cout << color[i] << endl;

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

    }

    return 0;

}




// Faster C++ solution for the same problem (measured speedup: 3.579391930054542x):
#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



*/