N,H,M,T=map(int,input().split()) M+=(N-1)*T H=(H+M//60)%24 M%=60 print("{}\n{}".format(H,M))