import java.io.InputStream
import java.math.BigDecimal
import java.math.BigInteger
import java.util.*

fun main(args: Array<String>) = input.run {
    val n = nextInt()
    val m = nextInt()

    val nodes = Array<Node>(n) { Node() }
    repeat(m) {
        val u = nodes[nextInt() - 1]
        val v = nodes[nextInt() - 1]
        u.siblings += v
        v.siblings += u
    }

    val q = nextInt()

    val queries = Array<Query>(q) {
        Query(time = it, start = nodes[nextInt() - 1], dist = nextInt(), color = nextInt())
    }

    queries.reverse()

    val queue: Queue<Node> = ArrayDeque()

    for (query in queries)  {
        val start = query.start
        if (start.query == null) {
            start.query = query
        }
        if (start.dist < query.dist) {
            start.dist = query.dist

            queue.add(start)

            while (queue.isNotEmpty()) {
                val cur = queue.remove()
                for (sibling in cur.siblings) {
                    if (sibling.query == null) {
                        sibling.query = query
                    }
                    if (sibling.dist < cur.dist - 1) {
                        sibling.dist = cur.dist - 1
                        queue.add(sibling)
                    }
                }
            }
        }
    }

    for (node in nodes) {
        println(node.query?.color ?: 0)
    }
}

class Node {
    val siblings = ArrayList<Node>()
    var query: Query? = null
    var dist = 0
}

class Query(val time: Int, val start: Node, val dist: Int, val color: Int)

val input = FastScanner()

fun String.toBigInteger() = BigInteger(this)
fun String.toBigDecimal() = BigDecimal(this)

class FastScanner(private val input: InputStream = System.`in`) {
    private val sb = StringBuilder()
    private val buffer = ByteArray(4096)
    private var pos = 0
    private var size = 0

    fun next(): String? {
        var c = skipWhitespace()
        if (c < 0) return null

        return sb.run {
            setLength(0)

            do {
                append(c.toChar())
                c = read()
            } while (c > ' '.toInt())

            toString()
        }
    }

    fun nextLine(): String? {
        var c = read()
        if (c < 0) return null

        return sb.run {
            setLength(0)

            while (c >= 0 && c != '\n'.toInt()) {
                append(c.toChar())
                c = read()
            }

            toString()
        }
    }

    fun nextLong(): Long {
        var c = skipWhitespace()

        val sign = if (c == '-'.toInt()) {
            c = read()
            -1
        } else 1

        var ans = 0L

        while (c > ' '.toInt()) {
            ans = ans * 10 + c - '0'.toInt()
            c = read()
        }

        return sign * ans
    }

    fun nextInt() = nextLong().toInt()
    fun nextDouble() = next()?.toDouble() ?: 0.0
    fun nextBigInteger(): BigInteger = next()?.toBigInteger() ?: BigInteger.ZERO
    fun nextBigDecimal(): BigDecimal = next()?.toBigDecimal() ?: BigDecimal.ZERO

    fun nextInts(n: Int) = IntArray(n) { nextInt() }
    fun nextLongs(n: Int) = LongArray(n) { nextLong() }
    fun nextDoubles(n: Int) = DoubleArray(n) { nextDouble() }
    fun nextBigIntegers(n: Int) = Array<BigInteger>(n) { nextBigInteger() }
    fun nextBigDecimals(n: Int) = Array<BigDecimal>(n) { nextBigDecimal() }

    fun nextInts(n: Int, m: Int) = Array(n) { nextInts(m) }
    fun nextLongs(n: Int, m: Int) = Array(n) { nextLongs(m) }
    fun nextDoubles(n: Int, m: Int) = Array(n) { nextDoubles(m) }
    fun nextBigIntegers(n: Int, m: Int) = Array(n) { nextBigIntegers(m) }
    fun nextBigDecimals(n: Int, m: Int) = Array(n) { nextBigDecimals(m) }

    private fun skipWhitespace(): Int {
        while (true) {
            val c = read()
            if (c > ' '.toInt() || c < 0) return c
        }
    }

    private fun read(): Int {
        while (pos >= size) {
            if (size < 0) return -1
            size = input.read(buffer, 0, buffer.size)
            pos = 0
        }
        return buffer[pos++].toInt()
    }
}


Measured memory_bytes: 63196