require "time" A,B,C,D = gets.split.map(&:to_i) T = (Time.parse("#{B}:#{C}") + 60 * (A - 1) * D) puts T.hour puts T.min