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