import java.util.Scanner; public class A000296 { 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(); sc.close(); int rh = h; int rm = m; rh+=((n-1)*t+m)/60; rm =((n-1)*t+m)%60; System.out.println(rh%24); System.out.println(rm); } }