#include <cstdio>
#include <cstdint>
#include <vector>
#include <algorithm>
#include <tuple>

template <typename Weight>
struct edge {
  using value_type = Weight;
  size_t src, dst;
  value_type cost;

  edge(size_t src, size_t dst, value_type cost = 1):
    src(src), dst(dst), cost(cost)
  {}

  bool operator <(edge<value_type> const& rhs) const {
    if (cost != rhs.cost) return cost < rhs.cost;
    if (src != rhs.src) return src < rhs.src;
    return dst < rhs.dst;
  }
};

template <typename Weight>
struct graph: public std::vector<std::vector<edge<Weight>>> {
  using value_type = Weight;
  graph(size_t n): std::vector<std::vector<edge<value_type>>>(n) {}

  void connect_to(size_t src, size_t dst, value_type cost = 1) {
    (*this)[src].emplace_back(src, dst, cost);
  }

  void connect_with(size_t src, size_t dst, value_type cost = 1) {
    connect_to(src, dst, cost);
    connect_to(dst, src, cost);
  }
};

void dfs(graph<int> const& g, std::vector<int>& a,
         size_t v, int d, int c) {

  if (a[v]) return;
  a[v] = c;
  if (d == 0) return;
  for (auto const& e: g[v]) {
    if (e.dst == v) continue;
    if (a[e.dst]) continue;
    dfs(g, a, e.dst, d-1, c);
  }
}

namespace detail {
template <typename Tp, size_t N>
std::vector<Tp> make_vector(
    std::vector<size_t>& sizes,
    typename std::enable_if<(N == 1), Tp const&>::type x
) {
  return std::vector<Tp>(sizes[0], x);
}
template <typename Tp, size_t N>
auto make_vector(
    std::vector<size_t>& sizes,
    typename std::enable_if<(N > 1), Tp const&>::type x
) {
  size_t size = sizes[N-1];
  sizes.pop_back();
  return std::vector<decltype(make_vector<Tp, N-1>(sizes, x))>(
      size, make_vector<Tp, N-1>(sizes, x)
  );
}
}  // detail::

template <typename Tp, size_t N>
auto make_vector(size_t const(&sizes)[N], Tp const& x) {
  std::vector<size_t> s(N);
  for (size_t i = 0; i < N; ++i) s[i] = sizes[N-i-1];
  return detail::make_vector<Tp, N>(s, x);
}

constexpr intmax_t  operator ""_jd(unsigned long long n) { return n; }
constexpr uintmax_t operator ""_ju(unsigned long long n) { return n; }
constexpr size_t    operator ""_zu(unsigned long long n) { return n; }
// constexpr ptrdiff_t operator ""_td(unsigned long long n) { return n; }

int main() {
  size_t N, M;
  scanf("%zu %zu", &N, &M);

  graph<int> g(N);
  for (size_t i = 0; i < M; ++i) {
    size_t a, b;
    scanf("%zu %zu", &a, &b);
    --a, --b;
    g.connect_with(a, b);
  }

  size_t Q;
  scanf("%zu", &Q);

  std::vector<std::tuple<size_t, int, int>> qs(Q);
  for (auto& q: qs) {
    size_t v;
    int d, c;
    scanf("%zu %d %d", &v, &d, &c);
    --v;
    q = std::make_tuple(v, d, c);
  }
  std::reverse(qs.begin(), qs.end());

  auto dp = make_vector<size_t>({N, 11_zu}, -1_zu);
  for (size_t i = 0; i < Q; ++i) {
    size_t v;
    int d, c;
    std::tie(v, d, c) = qs[i];
    dp[v][d] = std::min(dp[v][d], i);
  }

  for (size_t d = 11; d-- > 1;) {
    for (size_t v = 0; v < N; ++v) {
      dp[v][d-1] = std::min(dp[v][d-1], dp[v][d]);
      for (auto const& e: g[v]) {
        size_t u = e.dst;
        dp[u][d-1] = std::min(dp[u][d-1], dp[v][d]);
      }
    }
  }

  for (size_t i = 0; i < N; ++i) {
    if (dp[i][0]+1 == 0) {
      puts("0");
    } else {
      printf("%d\n", std::get<2>(qs[dp[i][0]]));
    }
  }
}


Measured memory_bytes: 23040