n,h,m,t=gets.split.map &:to_i m+=t*n-=1;h+=m/60;m%=60;puts h%24,m