n, h, m, t = gets.chomp!.split(' ').map(&:to_i) wakeup = (n - 1) * t m += wakeup if m > 59 m = (m % 59) - 1 h += 1 end h = (h % 23) -1 if h > 23 puts h puts m