// Slower C++ solution:
#include <bits/stdc++.h>

#define pb          emplace_back

#define ll          long long

#define fi          first

#define se          second

#define mp          make_pair



using namespace std;



template<typename T> inline void Cin(T &x)

{

    char c;

    T sign = 1;

    x = 0;

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

        if (c == '-') sign = -1;

    for (; c >= '0' && c <= '9'; c = getchar())

        x = x * 10 + c - '0';

    x *= sign;

}

template <typename T> inline void Out(T x) {if(x > 9) Out(x / 10); putchar(x % 10 + '0');}

template <typename T> inline void Cout(T x, char c) {if(x < 0) putchar('-'); x = abs(x); Out(x); putchar(c);}

template <typename T, typename... Args> inline void Cin(T& a, Args&... args) {Cin(a);Cin(args...);}

template <typename T, typename... Args> inline void Cout(T a, char c, Args... args) {Cout(a, c);Cout(args...);}



const int N = int(1e5) + 2;

typedef tuple<int, int, int> TQuery;



int color[N][11], n, m, u, v, d, c;

TQuery q[N];

vector<int> a[N];



void Paint(int u, int d) {

    if(color[u][d]) return;

    color[u][d] = c;

    if(d == 0) return;

    Paint(u, d - 1);

    for(int& v: a[u]) Paint(v, d - 1);

}



int32_t main() {

    ios_base::sync_with_stdio(0);

    cin.tie(0), cout.tie(0);

    #define Task        "test"

    if(fopen(Task".inp", "r")) {

        freopen(Task".inp", "r", stdin);

        freopen(Task".out", "w", stdout);

    }

    Cin(n, m);

    while(m --) Cin(u, v), a[u].pb(v), a[v].pb(u);

    Cin(m);

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

        Cin(v, d, c);

        q[i] = make_tuple(v, d, c);

    }

    while(m) {

        tie(v, d, c) = q[m --];

        Paint(v, d);

    }

    for(int i = 1; i <= n; ++i) Cout(color[i][0], '\n');

}


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

using namespace std;

typedef long long ll;

#define rep(i, n) for(int i = 0; i < (n); i++)

#define rep1(i, n) for(int i = 1; i <= (n); i++)

#define co(x) cout << (x) << "\n"

#define cosp(x) cout << (x) << " "

#define ce(x) cerr << (x) << "\n"

#define cesp(x) cerr << (x) << " "

#define pb push_back

#define mp make_pair

#define Would

#define you

#define please



const int cm = 1 << 17;

char cn[cm], * ci = cn + cm, ct;

inline char getcha() {

	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }

	return *ci++;

}

inline int getint() {

	int A = 0;

	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';

	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';

	return A;

}



const int dm = 1 << 20;

char dn[dm], * di = dn;

inline void putint(int X) {

	if (X == 0) {

		*di++ = '0';

		*di++ = '\n';

		return;

	}

	int keta = 0;

	char C[10];

	while (X) {

		*(C + keta) = '0' + X % 10;

		X /= 10;

		keta++;

	}

	for (int i = keta - 1; i >= 0; i--)* di++ = (*(C + i));

	*di++ = '\n';

}





pair<int, int> E[200001];

int H[200001];

int kotae[100001];

int Vis[100001];

void sagasu(int P, int D, int C) {

	if (D == 0 && kotae[P] == 0) kotae[P] = C;

	else if (Vis[P] < D) {

		Vis[P] = D;

		if (kotae[P] == 0) kotae[P] = C;

		for (int p = H[P]; p; p = E[p].second) {

			sagasu(E[p].first, D - 1, C);

		}

	}

}



int main() {

	cin.tie(0);

	ios::sync_with_stdio(false);





	int N, M, Q;

	N = getint();

	M = getint();

	for (int i = 1; i < 2 * M; i += 2) {

		int a = getint(), b = getint();

		E[i] = mp(a, H[b]);

		H[b] = i;

		E[i + 1] = mp(b, H[a]);

		H[a] = i + 1;

	}

	Q = getint();

	int v[100000], d[100000], c[100000];

	rep(i, Q) {

		v[i] = getint();

		d[i] = getint();

		c[i] = getint();

	}

	for (int i = Q - 1; i >= 0; i--) {

		sagasu(v[i], d[i], c[i]);

	}

	rep1(i, N) {

		putint(kotae[i]);

	}



	fwrite_unlocked(dn, di - dn, 1, stdout);



	Would you please return 0;

}