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