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