def add_time(original_h, original_m, spent_h, spent_m): new_m = (original_m + spent_m) % 60 if original_m + spent_m >= 60: over_flow_h = 1 else: over_flow_h = 0 new_h = (original_h + spent_h + over_flow_h) % 24 return new_h, new_m def main(): N, HOUR, MINUTE, INTERVAL = list( map(int, input().split()) ) all_minute_spent = INTERVAL * (N-1) hour_spent = all_minute_spent // 60 minute_spent = all_minute_spent % 60 new_h, new_m = add_time(HOUR, MINUTE, hour_spent, minute_spent) print(new_h) print(new_m) main()