N,H,M,T=map(int,input().split()) for _ in range(N-1): M+=T H+=M//60 M=M%60 H%=24 print(H) print(M)