import java.util.Scanner; public class Test { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n, h, m, t, tm, ah, am; n = sc.nextInt(); h = sc.nextInt(); m = sc.nextInt(); t = sc.nextInt(); tm = h*60 + m + t*(n-1); ah = (tm/60)%24; am = tm%60; System.out.println(ah); System.out.println(am); sc.close(); } }