#include <bits/stdc++.h>

using namespace std;

int main() {
   ios_base::sync_with_stdio(false); cin.tie(nullptr);
   int N, M;
   cin >> N >> M;
   vector<vector<int>> adj(N);
   for (int i = 0; i < M; ++i) {
      int v, u;
      cin >> v >> u;
      adj[--v].emplace_back(--u);
      adj[u].emplace_back(v);
   }
   int Q;
   cin >> Q;
   vector<int> color(Q + 1);
   vector<array<int, 11>> dp(N);
   for (int i = 1; i <= Q; ++i) {
      int v, d;
      cin >> v >> d >> color[i];
      dp[--v][d] = i;
   }
   for (int d = 10; d > 0; --d) {
      for (int v = 0; v < N; ++v) {
         dp[v][d - 1] = max(dp[v][d - 1], dp[v][d]);
         for (int u : adj[v]) {
            dp[u][d - 1] = max(dp[u][d - 1], dp[v][d]);
         }
      }
   }
   for (int i = 0; i < N; ++i) cout << color[dp[i][0]] << "\n";
   return 0;
}
