using System; using System.Collections.Generic; using System.Linq; namespace No296 { class MainClass { public static void Main (string[] args) { IList tokens = Console.ReadLine ().Split (' '); var f = tokens.Select(t=>(long)Convert.ToInt64(t)).ToArray(); long current = f [1] * 60 + f [2]; long add = (f [0]-1) * f [3]; long toDay = (current + add) % (24L * 60L); long hour = toDay / 60L; long minute = toDay % 60L; Console.WriteLine (hour.ToString ()); Console.WriteLine (minute.ToString ()); } } }