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