n, h, m, t = gets.split.map(&:to_i) x = m + t * (n - 1) a = (x + 60 * h) % 1440 / 60 b = x % 60 puts a, b