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