import java.util.Arrays; import java.util.HashSet; import java.util.LinkedList; import java.util.Scanner; import java.util.Set; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); final int N = sc.nextInt(); final int H = sc.nextInt(); final int M = sc.nextInt(); final int T = sc.nextInt(); long time = H * 60 + M; for(int i = 0; i < N - 1; i++){ time += T; } System.out.println((time / 60) % 24); System.out.println(time % 60); } }