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