import java.util.*

fun main(args: Array<String>) {
    Main().start()
}

class Main {
    lateinit var colors: IntArray
    lateinit var depth: IntArray
    lateinit var G: Array<MutableList<Int>>

    fun start() {
        val sc = Scanner(System.`in`)
        val N = sc.nextInt()
        val M = sc.nextInt()
        colors = IntArray(N)
        depth = IntArray(N) { -1 }
        G = Array<MutableList<Int>>(N) { mutableListOf() }
        repeat(M) {
            val a = sc.nextInt() - 1
            val b = sc.nextInt() - 1
            G[a].add(b)
            G[b].add(a)
        }
        val Q = sc.nextInt()
        val v = IntArray(Q)
        val d = IntArray(Q)
        val c = IntArray(Q)
        repeat(Q) {
            v[it] = sc.nextInt() - 1
            d[it] = sc.nextInt()
            c[it] = sc.nextInt()
        }
        for (i in Q - 1 downTo 0) {
            dfs(v[i], d[i], c[i])
        }
        colors.forEach(::println)
    }

    fun dfs(v: Int, d: Int, c: Int) {
        if (depth[v] >= d || d < 0) {
            return
        }
        depth[v] = d
        if (colors[v] == 0) {
            colors[v] = c
        }
        if (d > 0) {
            G[v].forEach { v -> dfs(v, d - 1, c) }
        }
    }
}
