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