#Sleep N times 296 N,H,M,T=(int(i) for i in input().split()) for i in range(N): M+=T h1=M//60 H+=h1 M%=60 H%=24 print(H) print(M)