import java.util.Scanner; 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 T = sc.nextInt(); sc.close(); int sleepMin = (N-1)*T; int minutes = (M+sleepMin)%60; int sleepHour = ((M+sleepMin)/60); H = (H+sleepHour)%24; System.out.println(H); System.out.println(minutes); }// mainmethod } // class