import java.util.*; public class Run { public static void main (String arg[]) { Scanner scan = new Scanner(System.in); int N = scan.nextInt(); int H = scan.nextInt(); int M = scan.nextInt(); int T = scan.nextInt(); int Th = T/60; int Tm = T%60; for (int i = 0; i < N - 1; i++) { M += Tm; if (M > 59) { H++; M %= 60; } H += Th; if (H > 23) H %= 24; } System.out.println(H + "\n" + M); } }