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