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