import java.util.Scanner; public class Main_yukicoder296 { 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 t = sc.nextInt(); long ret = m + 60 * h; long tmp = (long)(n - 1) * t; ret += tmp; ret %= 1440; System.out.println(ret / 60); System.out.println(ret % 60); sc.close(); } }