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