object Main extends App { val sc = new java.util.Scanner(System.in) val n,h,m,t = sc.nextInt println((h + (n - 1) * t / 60) % 24) println((n - 1) * t + m % 60) }