N,H,M,T = [int(i) for i in input().split()] M = M+T*(N-1) while M >= 60: M -= 60 H += 1 if H >= 24: H -= 24 print(H) print(M)