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