#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<n;++i)

using namespace std;

typedef pair<int,int>P;

const int MAX_N = 100005;

int n,m,Q;
vector<int> G[MAX_N];
int color[MAX_N];
int op[MAX_N][3];
int af[MAX_N];

void dfs(int num,int u,int dep,int D)
{
	if(af[u] >= D-dep){
		return;
	}
	af[u] = D-dep;
	if(color[u] == 0){
		color[u] = num;
	}
	if(D-dep>0){
		rep(i,G[u].size()){
			dfs(num,G[u][i],dep+1,D);
		}
	}
}

int main()
{
	int x,y;
	scanf("%d%d",&n,&m);
	rep(i,m){
		scanf("%d%d",&x,&y);
		G[x-1].push_back(y-1);
		G[y-1].push_back(x-1);
	}
	scanf("%d",&Q);
	rep(i,Q){
		scanf("%d%d%d",&op[i][0],&op[i][1],&op[i][2]);
	}
	rep(i,n){
		af[i] = -1;
	}
	for(int i=Q-1;i>=0;i--){
		dfs(op[i][2],op[i][0]-1,0,op[i][1]);
	}
	rep(i,n){
		printf("%d\n",color[i]);
	}
	return 0;
}