import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(), h = sc.nextInt(), m = sc.nextInt(), t = sc.nextInt(); int now = h * 60 + m + t * (n - 1); System.out.printf("%d\n%d\n", now / 60 % 24, now % 60); } }