// Reads multiple ints in a line, separate by a space.
// It works even if the actual number of ints is smaller than n.
// WARNING: This function does not work for -2^31.
// NOTE: This function does not handle error cases.
fun fastReadInts(n: Int): IntArray {
  val xs = IntArray(n)
  val s = readLine()!!
  var currentValue = 0
  var isNegative = false
  var currentIndex = 0
  for (c in s) {
    if (c == ' ') {
      xs[currentIndex] = currentValue * if (isNegative) -1 else 1
      currentValue = 0
      isNegative = false
      currentIndex++
    } else if (c == '-') {
      isNegative = true
    } else {
      currentValue *= 10
      currentValue += c - '0'
    }
  }
  xs[currentIndex] = currentValue * if (isNegative) -1 else 1
  return xs
}

class IntArray2D(val size1: Int, val size2: Int) {
  private val innerArray = IntArray(size1 * size2)

  operator fun get(i1: Int, i2: Int): Int = innerArray[i2 + size2 * i1]

  operator fun set(i1: Int, i2: Int, v: Int) {
    innerArray[i2 + size2 * i1] = v
  }
}

data class Query(val v: Int, val d: Int, val c: Int)

fun main(args: Array<String>) {
  val (n, m) = fastReadInts(2)
  val mutableGraph = Array(n, { mutableListOf<Int>() })
  repeat(m) {
    val (rawV1, rawV2) = fastReadInts(2)
    val v1 = rawV1 - 1
    val v2 = rawV2 - 1
    mutableGraph[v1].add(v2)
    mutableGraph[v2].add(v1)
  }
  val graph = mutableGraph.map { it.toIntArray() }

  val q = readLine()!!.toInt()
  val queries = Array(q, {
    val (vRaw, d, c) = fastReadInts(3)
    val v = vRaw - 1
    Query(v, d, c)
  })
  queries.reverse()

  val dp = IntArray2D(n, 11)

  fun dfs(v: Int, d: Int, c: Int) {
    if (dp[v, d] > 0) return
    for (k in d downTo 0) {
      if (dp[v, k] > 0) break
      dp[v, k] = c
    }

    if (d == 0) return

    for (u in graph[v]) {
      dfs(u, d - 1, c)
    }
  }

  for (query in queries) {
    dfs(query.v, query.d, query.c)
  }

  for (v in 0 until n) {
    println(dp[v, 0])
  }
}
