
def minute(time)
  h, m = time.split(":").map(&:to_i)
  h*60 + m
end

N, T = gets.split.map(&:to_i)
from, start, to, arrive = gets.split
pre = minute(to)
count = 0
answer = Array.new
(N-1).times do
  from, start, to, arrive = gets.split
  if (dif = minute(from) - pre) >= T
    count += 1
    answer.push("#{start} #{dif}")
  end
  pre = minute(to)
end
puts count, answer