import fs from 'node:fs' function main(input) { const n, h, m, t = readln().split(" ").map { it.toInt() }.toTypedArray() const a = ((h * 60 + m) + (n - 1) * t) % 1440 println(a / 60) println(a % 60) } main(fs.readFileSync('/dev/stdin', 'utf8'))