# -*- coding: utf-8 -*- import sys N, H, M, T = tuple(map(int, input().split())) N -= 1 if N == 0: print(H) print(M) sys.exit() for i in range(N): M += T if M >= 60: M -= 60 H += 1 if H >=24: H -= 24 print(H) print(M)