#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i = 0; i < (int)(n); ++i)
#define DEBUG(x) cerr << #x << " = " << x << endl
const int INF = (int)1e9;
int main() {
  int N, M; cin >> N >> M;
  vector<vector<int>> G(N);
  REP(i,M) {
    int a, b; cin >> a >> b;
    a--; b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  int Q; cin >> Q;
  vector<int> V(Q), D(Q), C(Q);
  REP(i,Q) {
    cin >> V[i] >> D[i] >> C[i];
    V[i]--;
  }
  static pair<int, int> d[11][100000];
  REP(i,11) REP(j,N) {
    d[i][j] = make_pair(0, 0);
  }
  REP(i,Q) {
    d[D[i]][V[i]] = make_pair(i + 1, C[i]);
  }
  for(int i = 10; i > 0; i--) {
    REP(j,N) {
      d[i-1][j] = max(d[i-1][j], d[i][j]);
      REP(k,G[j].size()) {
        d[i-1][G[j][k]] = max(d[i-1][G[j][k]], d[i][j]);
      }
    }
  }
  REP(i,N) {
    cout << d[0][i].second << endl;
  }
}
