import java.util.Scanner; 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 t = sc.nextInt(); m += ((n-1)*t); h += (m/60); m %= 60; h %= 24; System.out.println(h); System.out.println(m); } }