#include <bits/stdc++.h>

using namespace std;

int N, M, Q;
int color[100001];
vector<int> G[100001];
int v[100001],d[100001],c[100001];
int dp[100001];

void solve(int v,int d,int c) {
  if(dp[v] >= d) return;

  if(color[v] == 0) color[v] = c;

  dp[v] = d;

  for(int i = 0; i < G[v].size(); i++) {
    int u = G[v][i];
    solve(u,d-1,c);
  }
  
}


int main() {
  cin >> N >> M;

  for(int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }

  cin >> Q;

  for(int i = 0; i < Q; i++) {
    int vv,dd,cc;
    cin >> vv >> dd >> cc;
    vv--;
    v[i] = vv;
    d[i] = dd;
    c[i] = cc;
  }

  for(int i = Q-1; i >= 0; i--) {
    solve(v[i],d[i]+1,c[i]);
  }


  for(int i = 0; i < N; i++) cout << color[i] <<endl;
}
