fun main(args:Array<String>?): Unit {
    val n = readLine()!!.trim().toInt()
    val phrase = Array(n){
        val (s, l, p) = readLine()!!.trim().split(' ').map(String::toInt)
        Phrase(s, l, p)
    }
    val length = Array(394){Phrase(0, 0, 0)}
    length[phrase.first().minLength] = phrase.first()
    for (i in 1 until phrase.size){
        val p = phrase[i]
        for (j in 0 .. 393) {
            if (length[j].minLength > 0 || j == 0){
                var new = p + length[j]
                while(new.minLength <= 393) {
                    val old = length[new.minLength]
                    if (new.maxLength >= old.maxLength && new.point >= old.point) {
                        length[new.minLength] = new
                        break
                    } else if (new.maxLength <= old.maxLength && new.point <= old.point) {
                        break
                    }else {
                        length[new.minLength] = Phrase(new.minLength, Math.min(new.maxLength, old.maxLength), Math.max(new.point, old.point))
                        new = Phrase(Math.min(new.maxLength, old.maxLength) + 1, Math.max(new.maxLength, old.maxLength), Math.min(new.point, old.point))
                    }
                }
            }
        }
    }
    val maxPoint = IntArray(394){-1}
    for (p in length) if (p.point > 0){
        for (i in p.minLength .. Math.min(393, p.maxLength)) maxPoint[i] = Math.max(maxPoint[i], p.point)
    }
    println(IntArray(readLine()!!.trim().toInt()){maxPoint[readLine()!!.trim().toInt()]}.takeUnless{it.contains(-1)}?.joinToString("\n") ?: -1)
}
data class Phrase(val minLength: Int, val maxLength: Int, val point: Int) {
    operator fun plus(that: Phrase): Phrase = Phrase(minLength + that.minLength, maxLength + that.maxLength, point + that.point)
}
