Woburn Challenge 2002

Problem 1: A Planning Session

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 ≤ N ≤ 32000). 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.

Input

The first line of input contains a single integer T (1 ≤ T ≤ 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 ≤ HH ≤ 12 and 00 ≤ MM ≤ 59, indicating the current time in Scarberia.
The second line contains a single integer, N.

Output

A single integer that is the number of minutes left before a meeting occurs or "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 possible.

Sample Input

3
11:59
3
01:00
15
12:11
33

Sample Output

1
59
Infinite

All Submissions
Best Solutions


Point Value: 5
Time Limit: 2.00s
Memory Limit: 16M
Added: Sep 30, 2008

Languages Allowed:
C++03, PAS, C, HASK, ASM, RUBY, PYTH2, JAVA, PHP, SCM, CAML, PERL, C#, C++11, PYTH3

Comments (Search)

The one which got 7/8

In the future, please try indenting =). It makes it much more readable