#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#define sqr(x) (x)*(x)
using namespace std;
int n,m,q,i,j,vis[100005],col[100005],cen[100005],dis[100005],c[100005],x,y;
vector<int> bi[100005];
void dfs(int x,int y,int z)
{
	if (vis[x]>=y) return;
	vis[x]=y;
	if (!col[x]) col[x]=z; 
	int i;
	for (i=0;i<bi[x].size();i++)
	{
		dfs(bi[x][i],y-1,z);
	}
}
int main()
{
	ios_base::sync_with_stdio(0);
	cin>>n>>m;
	for (i=1;i<=m;i++)
	{
		cin>>x>>y;
		bi[x].push_back(y);
		bi[y].push_back(x);
	}
	cin>>q;
	for (i=1;i<=q;i++) cin>>cen[i]>>dis[i]>>c[i];
	for (i=q;i>0;i--)
	{
		dfs(cen[i],dis[i]+1,c[i]);
	}
	for (i=1;i<=n;i++) cout<<col[i]<<endl;
	return 0;
}