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