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