N,H,M,T=map(int,raw_input().split()) n=H*60+M n+=T*(N-1) h=int(n/60) m=n%60 print h%24 print m