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