// 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: 1.9558980776377217x):
#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;

}