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