N, H, M, T = map(lambda x: int(x), input().split()) add = (N - 1) * T M += add H, M = (H + M // 60) % 24, M % 60 print(H) print(M)