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