# include <iostream>
# include <cmath>
# include <algorithm>
# include <stdio.h>
# include <cstdint>
# include <cstring>
# include <string>
# include <cstdlib>
# include <vector>
# include <bitset>
# include <map>
# include <queue>
# include <ctime>
# include <stack>
# include <set>
# include <list>
# include <random>
# include <deque>
# include <functional>
# include <iomanip>
# include <sstream>
# include <fstream>
# include <complex>
# include <numeric>
# include <immintrin.h>
# include <cassert>
# include <array>
# include <tuple>
# include <unordered_map>
# include <unordered_set>
# include <thread>

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using ui32 = unsigned int;
constexpr ll INFLL = 1e18;

#define CHECK_IMPL1(cond)              \
if (!(cond)) {                         \
    DEBUG("expected cond: " << #cond); \
    assert(cond);                      \
}

#define CHECK_IMPL2(cond, message)                                            \
if (!(cond)) {                                                                \
    DEBUG("expected cond: " << #cond << " failed with message: " << message); \
    assert(cond);                                                             \
}
#define CHECK_IMPL(_1, _2, NAME, ...) NAME
#define CHECK(...) CHECK_IMPL(__VA_ARGS__, CHECK_IMPL2, CHECK_IMPL1, CHECK_IMPL0)(__VA_ARGS__)

#ifdef __APPLE__
#define DEBUG(message) std::cerr << message << "\n";
#else
#define DEBUG(message)
#endif

struct Solver {
  void solve() {
    cin >> n >> m;

    g.resize(n);
    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;
    v.resize(q);
    d.resize(q);
    c.resize(q);

    queues.resize(D + 1);
    dist.resize(n);
    color.resize(n, 0);
    used.resize(n, false);
    for (int i = 0; i < n; i++) {
      dist[i].resize(D + 1);
      for (int j = 0; j <= D; j++) {
        dist[i][j] = { -1, -1 };
      }
    }
    for (int i = 0; i < q; i++) {
      cin >> v[i] >> d[i] >> c[i];
      --v[i];

      for (int j = 0; j <= d[i]; j++) {
        dist[v[i]][j] = {c[i], i};
      }
    }

    DEBUG("input done");

    for (int i = 0; i < n; i++) {
      auto queue_number = get_queue_number(i);
      if (queue_number < 0) {
        continue;
      }
      queues[queue_number].push(i);
    }

    DEBUG("initialized");
    for (int v = 0; v < n; v++) {
      DEBUG("v: " << v + 1);
      for (int i = 0; i <= D; i++) {
        DEBUG("d[" << i << "] = " << dist[v][i].first << " " << dist[v][i].second);
      }
    }

    while (true) {
      auto v = get_vertex();
      if (v == -1) {
        break;
      }

      DEBUG("v: " << v + 1);
      for (int i = 0; i <= D; i++) {
        DEBUG("d[" << i << "] = " << dist[v][i].first << " " << dist[v][i].second);
      }

      auto temp = dist[v];
      for (int i = 0; i < D; i++) {
        temp[i] = temp[i + 1];
      }
      temp[D] = { -1, -1 };
      if (temp[0].first == -1) {
        continue;
      }

      for (auto u : g[v]) {
        auto res = dist[u];
        bool improved = false;
        for (int i = 0; i <= D; i++) {
          if (temp[i].first == -1) {
            break;
          }
          if (res[i].second < temp[i].second) {
            improved = true;
            res[i] = temp[i];
          }
        }
        if (!improved) {
          continue;
        }
        for (int i = 0; i < D; i++) {
          CHECK(res[i].second >= res[i + 1].second);
        }
        dist[u] = res;
        auto queue_number = get_queue_number(u);
        DEBUG("u: " << u + 1 << " queue number: " << queue_number << " color: " << res[0].first);
        if (queue_number < 0) {
          continue;
        }
        queues[queue_number].push(u);
      }
    }

    DEBUG("final");
    for (int v = 0; v < n; v++) {
      DEBUG("v: " << v + 1);
      for (int i = 0; i <= D; i++) {
        DEBUG("d[" << i << "] = " << dist[v][i].first << " " << dist[v][i].second);
      }
    }

    for (int i = 0; i < n; i++) {
      if (dist[i][0].first != -1) {
        color[i] = dist[i][0].first;
      }
      cout << color[i] << "\n";
    }
  }

  int get_vertex() {
    for (int i = D; i >= 0; i--) {
      if (!queues[i].empty()) {
        auto v = queues[i].front();
        queues[i].pop();
        return v;
      }
    }
    return -1;
  }

  int get_queue_number(int v) {
    for (int j = 0; j <= D; j++) {
      if (dist[v][j].first == -1) {
        return j - 1;
      }
    }
    return D;
  }

  static constexpr size_t D = 10;

  int n;
  int m;
  int q;
  vector<vector<int>> g;
  vector<int> v;
  vector<int> d;
  vector<int> c;

  vector<vector<pair<int, int>>> dist;
  vector<int> color;
  vector<bool> used;
  vector<queue<int>> queues;
};

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
#ifdef __APPLE__
  freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);
#endif
  int t = 1;
//  cin >> t;
  for (int i = 1; i <= t; i++) {
    Solver().solve();
  }
  return 0;
}

Measured memory_bytes: 23404