import java.util.Scanner; class Main { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int n = scan.nextInt(); int h = scan.nextInt(); int m = scan.nextInt(); int t = scan.nextInt(); int tmp = (n - 1) * t; int ch = tmp / 60; int cm = tmp - ch * 60; if ( (m += cm) >= 60 ) { m -= 60; ch++; } if ( (h += ch) >= 24 ) { h -= 24; } System.out.println(h); System.out.println(m); scan.close(); } }