Woburn Challenge 2002
The cows have been advancing steadily against a weak monkeys' front. The Head-Monkey, employing logic not used since the debacle of the Polish Un-Truth Table, decides to expose the monkeys' backs, hoping for better luck. Unfortunately, this tactic is not successful, and the monkeys are forced to retreat further into the deep recesses of Scarberia, with sore bottoms, no less.
The Head-Monkey decides it's time for action. But before anything can be done, a meeting must be called to decide what must be done. And in this meeting, several debates must be fought, each lasting several hours, and each leading to the inevitable conclusion, "Just leave it as it was last year!" The Head-Monkey sends forth word to her disciples to meet at the top of the Enchanted Tree at the next time when the digits of the time sum to a certain number, ~N~ ~(1 \le N \le 32\,000)~. Several of the younger monkeys want to continue playing their games for as long as possible, and consequently, want to know how many minutes are left before the meeting is to begin.
The first line of input contains a single integer ~T~ ~(1 \le T \le
50)~, indicating the number of test cases. Each test case consists of
two lines; the first line contains a string in the form ~HH~:~MM~, where ~01
\le HH \le 12~ and ~00 \le MM \le 59~, indicating the current time in
The second line contains a single integer, ~N~.
A single integer that is the number of minutes left before a meeting
Infinite if a meeting never occurs. Note that the output
will never be ~0~ since we are asking for THE NEXT TIME when a meeting is
3 11:59 3 01:00 15 12:11 33
1 59 Infinite