import java.util.*; 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(); M = M + (N-1)*T; while(M>=60){ M=M-60; H++; } if(H>=24){ H=H-24; } System.out.println(H); System.out.println(M); } }