import java.util.Scanner; public 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(); scan.close(); int t = H * 60 + M; int max = 24 * 60; int k = ((N - 1) * T) % max; //System.out.println(k); int m = 0; if(k <= max - t) { m = t + k; }else { m = k - (max - t); } int ans1 = m / 60; int ans2 = m % 60; if(ans1 == 24) { System.out.println(0); System.out.println(0); System.exit(0); } System.out.println(ans1); System.out.println(ans2); } }