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