import java.util.Scanner; public class Yukicoder296 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(), h = sc.nextInt(), m = sc.nextInt(), t = sc.nextInt(); m += t * (n - 1); h += m / 60; h %= 24; m %= 60; System.out.println(h + "\n" + m); } }