n,h,m,t=gets.split(" ").map(&:to_i) y=m+t*(n-1) puts"#{(h+y/60)%24}\n#{y%60}"