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