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

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

}