// Slower C++ solution:
/*

Till the roof comes off, till the lights go out

Till my legs give out, canâ��t shut my mouth.

Till the smoke clears out. Am I high? Perhaps

I'ma rip this shit till my bones collapse.

*/

#include <stdio.h>

#include <iostream>

#include <algorithm>

#include <vector>

#include <deque>

#include <set>

#include <stack>

#include <string.h>

#include <map>

#include <vector>

#include <queue>

#include <math.h>

#include <stack>

#include <complex>





#define ll long long

#define X real()

#define Y imag()

#define f first

#define s second

#define angle(a)                (atan2((a).imag(), (a).real()))

#define vec(a,b)                ((b)-(a))

#define same(p1,p2)             (dp(vec(p1,p2),vec(p1,p2)) < EPS)

#define dp(a,b)                 ( (conj(a)*(b)).real() )	// a*b cos(T), if zero -> prep

#define cp(a,b)                 ( (conj(a)*(b)).imag() )	// a*b sin(T), if zero -> parllel

#define lngth(a)               (hypot((a).imag(), (a).real()))

#define normalize(a)            (a)/length(a)



using namespace std;



const int N=200005;

typedef pair<ll,int>ii;

typedef pair<ii,int>event;

typedef complex<double>point;

const double EPS = 1e-9;

const int INF=100000;



const double PI = acos(-1);

int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }



int n,m,a[N],d[N],c[N],mx[N],sol[N];

vector<int>adj[N];

bool v[N][12];

void bfs(int node,int dep,int col){

   if(mx[node]>dep)return;

   queue<int>q;

   q.push(node);

   q.push(dep);

   v[node][dep]=1;

  if(mx[node]==-1)

   sol[node]=col;

   mx[node]=dep;

   while(q.size()){

        node=q.front();

        q.pop();

        dep=q.front();

        q.pop();

        if(!dep)continue;

        for(int i=0;i<adj[node].size();i++){

            int to=adj[node][i];

            if(mx[to]>=dep-1)continue;

           if(mx[to]==-1)

            sol[to]=col;

            mx[to]=dep-1;

            q.push(to);

            q.push(dep-1);

        }

   }

}

int main()

{

    //freopen("test.in","r",stdin);

   //freopen("output.txt","w",stdout);

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

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

        int a,b;

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

        adj[a].push_back(b);

        adj[b].push_back(a);

    }

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

    int q;

    scanf("%d",&q);

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

        scanf("%d%d%d",&a[i],&d[i],&c[i]);

    memset(sol,0,sizeof(sol));

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

        bfs(a[i],d[i],c[i]);

    }

    for(int i=1;i<=n;i++)cout<<sol[i]<<endl;

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 2.362974542366208x):
#include<bits/stdc++.h>

using namespace std;

#define C getchar()

inline int read() {

	int num = 0;

	char c = C;

	for(;c<'0' || c>'9';c=C);

	for(;c>='0' && c<='9';c=C) num = (num << 1) + (num << 3) + (c ^ 48);

	return num;

}



//int nxt[200010],head[100010],to[200010],tot;

//

//inline void add(int x,int y) {

//	nxt[++tot] = head[x],head[x] = tot,to[tot] = y;

//}



int vis[100010][12];



vector<int> edge[100010];



inline void putc(int x,int d,int cl) {

	if (d == -1) return ;

	if (vis[x][d]) return ;

	vis[x][d] = cl;

	for(int i=0;i<edge[x].size();++i) putc(edge[x][i] , d - 1 , cl);

}



int n,m,Q;

struct node {

	int rt,d,cl;

}a[100010];



int main() {

//	freopen("1.in","r",stdin);

//	freopen("d.out","w",stdout);

	n = read(),m = read();

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

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

		edge[u].push_back(v);

		edge[v].push_back(u);

//		add(u , v);add(v , u);

	}

//	for(int i=1;i<=n;++i) add(i , i);

  for(int i=1;i<=n;++i) edge[i].push_back(i);

	

	Q = read();

	for(int i=1;i<=Q;++i) a[i].rt = read(),a[i].d = read(),a[i].cl = read();

	for(int i=Q;i>=1;--i) putc(a[i].rt , a[i].d , a[i].cl);

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

	return 0;

}