import java.util.*; import java.math.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int h = sc.nextInt(); int m = sc.nextInt(); int t = sc.nextInt(); Time time = new Time(h, m); if (n <= 1) { time.getTime(); System.exit(1); } time.setMin((n - 1) * t); time.getTime(); } } class Time { private int hour; private int min; public Time(int a, int b) { hour = a; min = b; } public void setTime(int a, int b) { if (min + b >= 60) { hour++; this.min = Math.abs(min - b); } else { this.min += b; } if (hour + a >= 24) { this.hour = Math.abs((24 - this.hour) - a); } else { this.hour += a; } } public void setMin(int a) { int m = this.min + a; int h = this.hour; if (m >= 60) { h = this.hour + (int)Math.floor(m / 60); m = m % 60; } if (h >= 24) { h = h % 24; } this.hour = h; this.min = m; } public void getTime() { System.out.println(this.hour); System.out.println(this.min); } }