n, h, m, t = gets.chomp.split.map(&:to_i)

x = (h * 60 + m) + (n - 1) * t

puts (x / 60) % 24
puts x % 60