#include <bits/stdc++.h>

typedef long long ll;
 
const int maxn = 1e5 + 10;
 
int f[maxn][11], cor[maxn];
int a[maxn], b[maxn], c[maxn];
int n, m, q, x, y;
 
std::vector <int> v[maxn];
 
void Work(int x, int y, int z){
	if (~f[x][y]) return;
	if (!cor[x]) cor[x] = z;
	if (y <= 0) return;
	for (auto u : v[x]){
		Work(u, y - 1, z);
	}
	f[x][y] = 1;
}

int read(){ int x = 0, ch = getchar(), f = 1; while(!isdigit(ch)){if(ch == '-')f = -1; ch = getchar();} while(isdigit(ch)){ x = x * 10 + ch - '0', ch = getchar();} return x * f; }
 
int main()
{
    // freopen(".in","r",stdin); freopen(".out","w",stdout);
    n = read(), m = read();
	for(int i = 1; i <= m; ++ i) x = read(), y = read(), v[x].push_back(y), v[y].push_back(x);
    q = read();
	for( int  i = 1; i <= n; ++ i ) a[i] = read(), b[i] = read(), c[i] = read();
	memset(f, -1, sizeof f);
	for( int i = q; i >= 1; i --) Work(a[i], b[i], c[i]);
	for(int i = 1; i <= m ; ++ i) printf("%d\n", cor[i]);
	return 0;
}