n, h, m, t = list(map(int, input().split())) x = m + t * (n - 1) print((h + x // 60) % 24) print(x % 60)