n, h, m, t = gets.chomp.split(" ").map(&:to_i) t = t * (n - 1) m += t if m > 59 h += 1 m -= 60 if h > 23 h = 0 end end puts h puts m