require "matrix"

n, t = gets.split.map(&:to_i)
output = []

_, _, prev_ar_time, _ = gets.split
while gets
    st_time, st_name, ar_time, ar_name = $_.split

    v = [st_time, prev_ar_time]
        .map{|s| s.split(":").map(&:to_i)}
        .map{|a| Vector[*a]}
        .inject(&:-)
    x = v[0] * 60 + v[1]

    output << "#{st_name} #{x}" if x >= t
    prev_ar_time = ar_time
end

puts output.size
puts output.join($/)