import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class No00000296_Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String[] arr = br.readLine().split(" "); int n = Integer.parseInt(arr[0]); int h = Integer.parseInt(arr[1]); int m = Integer.parseInt(arr[2]); int t = Integer.parseInt(arr[3]); System.out.println((h + (m + (n - 1) * t) / 60) % 24); System.out.println((m + (n - 1) * t) % 60); } }