import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); long N = sc.nextLong(); long H = sc.nextLong(); long M = sc.nextLong(); long T = sc.nextLong(); long wake = (N - 1) * T + 60 * H + M; wake = wake % ((long)(60 * 24)); long ansh = wake / 60; long ansm = wake - 60 * ansh; System.out.println(ansh); System.out.println(ansm); } }