N, H, M, T = gets.chomp.split.map(&:to_i) m = M + T * (N - 1) h = H while m < 60 h += 1 m /= 60 end puts h puts m % 60