M = list(map(int, input().split())) for i in range(M[0] - 1): M[2] += M[3] if M[2] >= 60: M[1] += 1 M[2] -= 60 print(M[1]) print(M[2])