function Main(input) {
  const data = input.trim().split(" ")
  let N = parseInt(data[0]), H = parseInt(data[1]), M = parseInt(data[2]), T = parseInt(data[3])
  M += T * (N - 1)
  H += ~~(M / 60)
  console.log(~~(H % 24))
  console.log(~~(M % 60))
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"))