import java.util.Scanner; 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(); m += t * (n - 1); h += m / 60; h = h % 24; m = m % 60; System.out.print(h + "\n" + m + "\n"); } }