N, H, M, T = [int(i) for i in input().strip().split(' ')] M += T * (N - 1) H += M // 60 M = M % 60 print(H % 24) print(M)