import java.util.*; import java.lang.*; import java.io.*; class Main { 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(); int stime =(n-1)*t; int sh = stime/60; int ah =(h + sh)%24; int sm = stime%60; int am = (m + sm)%60; System.out.println(ah); System.out.println(am); } }