import java.util.*; public class Main{ public static void main(String[] args){ int i; Scanner sc = new Scanner(System.in); String[] line = sc.nextLine().split(" "); int[] time = new int[4]; for(i=0;i<4;i++)time[i] = Integer.parseInt(line[i]); time[2] = time[2] + (time[0] - 1) * time[3]; while(time[2] > 1440){ time[2] -= 1440; } while(time[2]>59){ time[1]++; if(time[1]>23){ time[1] = 0; } time[2] = time[2] - 60; } System.out.println(time[1] + "\n" + time[2]); } }