import math._ object Main { def main(args: Array[String]) { val sc = new java.util.Scanner(System.in) val n, h, m, t = sc.nextInt val time = h * 60 + m + (n - 1) * t println((time / 60) % 24) println(time % 60) } }