import java.util.*


data class Time(val hour: Int, val minute: Int) {
    constructor(times: List<Int>):this(times[0], times[1])
    constructor(expression: String):this(expression.split(':').map(String::toInt))
    private constructor(second: Int):this(second / 3600, (second % 3600) / 60)
    private val second: Int
        get() = hour * 3600 + minute * 60
    val wholeMinutes: Int
        get() = hour * 60 + minute
    operator fun minus(other: Time): Time = Time((second - other.second + 86400) % 86400)
}
fun main(args: Array<String>?): Unit {
    val (n, t) = readLine()!!.trim().split(' ').map(String::toInt)
    val stations = Array(n){
        val (st, sn, at, an) = readLine()!!.trim().split(' ')
        listOf(Pair(Time(st), sn), Pair(Time(at), an))
    }
    val stack = Stack<Pair<String, Int>>()
    for (i in 1 until n){
        if ((stations[i][0].first - stations[i - 1][1].first).wholeMinutes >= t) {
            stack.push(Pair(stations[i][0].second,(stations[i][0].first - stations[i - 1][1].first).wholeMinutes))
        }
    }
    println(stack.size)
    for ((name, time) in stack) {
        println("$name $time")
    }
}
