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