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