// 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: 2.516692926054588x):
#include<cstdio>

#include<iostream>

#include<queue>

#include<cstring>

#define N 100010

using namespace std;

struct Dis{

	int x,z;

};

queue<Dis>Q;

int a[N],c[N],d[N],e[N],f[N],num,h[N],n,m,p,q,t,col;

bool bo[N];

struct Edge{

	int p,q,n;

}b[N*2];

void ljb(int p,int q){

	b[++num].n=h[p];

	h[p]=num;

	b[num].p=p;

	b[num].q=q;

}

void Bfs(){

	int x,y,z;

	while(!Q.empty()){

		x=Q.front().x; z=Q.front().z; Q.pop(); 

//		printf("%d %d\n",x,z);

		if(!f[x])f[x]=col;

		e[x]=max(e[x],z);

		if(z==0)continue;

		for(int i=h[x];i!=0;i=b[i].n){

			y=b[i].q;

			if(e[y]<z-1)Q.push((Dis){y,z-1});

		}

	}

}

int main(){

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

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

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

		scanf("%d%d",&p,&q);

		ljb(p,q);

		ljb(q,p);

	}

	scanf("%d",&t);

	for(int i=1;i<=t;i++)scanf("%d%d%d",&a[i],&d[i],&c[i]);

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

		if(e[a[i]]>=d[i])continue;

		col=c[i];

		Q.push((Dis){a[i],d[i]});

		Bfs();

	}

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

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

}