n, h, m, t = gets.split.map(&:to_i) time = (h * 60 + m + (n - 1) * t) % (24 * 60) puts time / 60, time % 60