# coding:utf-8 N, H, M, T = map(int, input().split()) N_C = 0 H_C = H M_C = M while True: N_C += 1 if N_C == N: break else: M_C += T if M_C >= 60: M_C -= 60 H_C += 1 else: if H_C >= 24: H_C -= 24 else: continue print(H_C) print(M_C)