N,H,M,T=map(int,input().split()) A=H*60+M B=(N-1)*T C=(A+B)%(24*60) h=C//60 m=C%60 print(h) print(m)