// 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.325643666312887x):
#include "bits/stdc++.h"

using namespace std;

#ifndef LOCAL

#define endl '\n'

#endif



#define fr(i, a, b) for(int i = a; i <= b; i++)

#define rf(i, a, b) for(int i = a; i >= b; i--)

#define pf push_front

#define pb push_back

#define eb emplace_back

#define fi first

#define se second

#define all(x) x.begin(), x.end()

#define rall(x) x.rbegin(), x.rend()

#define sz(x) (int)x.size()

#define lb lower_bound

#define ub upper_bound



typedef long long ll;

typedef long double f80;

typedef pair<int,int> pii;

typedef pair<ll,ll> pll;



int pct(int x) { return __builtin_popcount(x); }

int pct(ll x) { return __builtin_popcountll(x); }

int bt(int x) { return 31 - __builtin_clz(x); } // floor(log2(x))

int bt(ll x) { return 63 - __builtin_clzll(x); } // floor(log2(x))

int cdiv(int a, int b) { return a / b + !(a < 0 || a % b == 0); }

ll cdiv(ll a, ll b) { return a / b + !(a < 0 || a % b == 0); }

int nxt_C(int x) { int c = x & -x, r = x + c; return (((r ^ x) >> 2) / c) | r; }

ll nxt_C(ll x) { ll c = x & -x, r = x + c; return (((r ^ x) >> 2) / c) | r; }



vector<int> get_bits(int mask) {

	vector<int> bb;

	while(mask) { int b = bt(mask); bb.pb(b); mask ^= (1 << b); }

	reverse(all(bb));

	return bb;

}



int get_mask(vector<int> v) {

	int mask = 0;

	for(int x : v) { mask ^= (1 << x); }

	return mask;

}



template<typename T>

void uniq(vector<T> &v) { sort(all(v)); v.resize(unique(all(v)) - v.begin()); }



mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());



ll rand(ll l, ll r){

	uniform_int_distribution<ll> uid(l, r);

	return uid(rng);

}



void sc() {}



template <typename Head, typename... Tail>

void sc(Head &H, Tail &... T) { cin >> H; sc(T...); }



#ifdef LOCAL

#define debug(...) cerr << "[L:" << __LINE__ << "][" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

#else

#define debug(...) 42

#endif



// #ifndef LOCAL

// string to_string(__int128 x) {

// 	string s = "";

// 	bool neg = 0;

// 	if(x < 0) { s += "-"; neg = 1; x = -x; }

// 	if(!x) s += '0';

// 	while(x) {

// 		int rem = x % 10;

// 		s += to_string(rem);

// 		x /= 10;

// 	}

// 	reverse(s.begin() + neg, s.end());

// 	return s;

// }

// #endif



const int mod = 1e9 + 7; // 998244353;



int pwr(int a,ll b) {

	int ans = 1;

	while(b) {

		if(b & 1) ans = (ans * 1LL * a) % mod;

		a = (a * 1LL * a) % mod;

		b >>= 1;

	}

	return ans;

}



/*

	Lookout for overflows!!

	Check array sizes!!

	Clear before test cases!!

	Use the correct modulo!!

	Check for corner cases!!

	Are you forgetting something?!

	Read problem statement carefully!!!

*/



const int N = 1e5 + 5;

int U[N], D[N], C[N];

vector<int> g[N];

bool vis[N][11];

int color[N];



void solve() {

	int n, m;

    sc(n, m);

    fr(i, 1, m) {

        int u, v;

        sc(u, v);

        g[u].pb(v);

        g[v].pb(u);

    }

    int q;

    sc(q);

    fr(i, 1, q) {

        sc(U[i], D[i], C[i]);

    }

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

        if(vis[U[i]][D[i]]) continue;

        vis[U[i]][D[i]] = 1;

        queue<pii> q;

        q.push({U[i], D[i]});

        while(!q.empty()) {

            pii u = q.front();

            q.pop();

            if(!color[u.fi]) color[u.fi] = C[i];

            if(u.se == 0) continue;

            for(int v : g[u.fi]) {

                if(!vis[v][u.se - 1]) {

                    vis[v][u.se - 1] = 1;

                    q.push({v, u.se - 1});

                }

            }

        }

    }

    fr(i, 1, n) {

        cout << color[i] << endl;

    }

}



int main() {

	ios :: sync_with_stdio(0);

	cin.tie(0);

	cout.tie(0);

	int t = 1;

	// cin >> t;

	for(int tt = 1; tt <= t; tt++) {

		solve();

	}

	return 0;

}