N, H, M, T = map(int, input().split()) M += (N - 1) * T if M >= 60: H += 1 min_left = M - 60 M = min_left if H > 24: H = 0 print(H) print(M)