// Original C++ solution (slower):
#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;



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

typedef tuple<int, int, int> TQuery;



int color[N][11], n, m, Q, 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;

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

        cin >> u >> v;

        a[u].pb(v), a[v].pb(u);

    }

    cin >> Q;

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

        cin >> v >> d >> c;

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

    }

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

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

        Paint(v, d);

    }

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

}


// Optimized solution to the same problem (faster):
#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;

}


// Fastest known solution for this problem: