#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>;
#include <cstring>
#define ll long long 
using namespace std;
const int maxn=1e5+10;
struct edge
{
  int y;
  int next_;
  int v;
}e[maxn<<1];
int n,m;
int lin[maxn];
int len=0;
int vis[maxn];
struct node
{
  int x;
  int dist;
  int id;
}a[maxn];
int col[maxn];
int t;
inline void Iinsert(int x,int y)
{
  e[++len].next_=lin[x];
  lin[x]=len;
  e[len].y=y;
}
inline void init()
{
  scanf("%d%d",&n,&m);
  for(int i=1;i<=m;i++)
  {
    int x,y,v;
    scanf("%d%d",&x,&y);
    Iinsert(x,y);
    Iinsert(y,x);
  }
  scanf("%d",&t);
  for(int i=1;i<=t;i++)
    scanf("%d%d%d",&a[i].x,&a[i].dist,&a[i].id);
}
inline void dfs(int x,int dist,int id,int sum)
{
  if(sum>dist)
    return;
  vis[x]=true;
  col[x]=id;
  for(int i=lin[x];i;i=e[i].next_)
  {
    int y=e[i].y;
    dfs(y,dist,id,sum+1);
  }
}
inline void work_()
{
  for(int i=1;i<=t;i++)
  {
  	//if(vis[a[i].x])
  	  //continue;
    dfs(a[i].x,a[i].dist,a[i].id,0);
    //cout<<"qaq"<<endl;
  }
  for(int i=1;i<=n;i++)
    printf("%d\n",col[i]);
}
int main()
{
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	init();
	work_();
	return 0;
}
