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