n, h, m, t = map(int, input().split()) m += (n - 1) * t print(f"{(h + m // 60) % 24}\n{m % 60}")