import java.util.*; class Main { static Scanner sc = new Scanner(System.in); public static void main(String[] args) { int n = sc.nextInt(); int h = sc.nextInt(); int m = sc.nextInt(); int t = sc.nextInt(); Calendar cl = Calendar.getInstance(); cl.set(Calendar.HOUR_OF_DAY, h); cl.set(Calendar.MINUTE, m); cl.add(Calendar.MINUTE, (n-1)*t); System.out.println(cl.get(Calendar.HOUR_OF_DAY)); System.out.println(cl.get(Calendar.MINUTE)); } }