n,h,m,t = gets.split.map(&:to_i) w = h * 60 + m + (n - 1) * t h, m = w.divmod(60) puts [h % 24, m]