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