Time Warp

No attempts yetTime limit3sMemory limit256 MB

Problem

Tim tells the time in his own way. Ask him and he might answer 20 after 8, which sounds ordinary, or 90 after 8 and 126 til 4, which do not.

Tim's rule is this. 20 after 8 is the first time after 8 o'clock at which the hour hand and the minute hand make an angle of 20 degrees. 126 til 4 is the time closest to 4 o'clock among the times before 4 o'clock at which the two hands make an angle of 126 degrees.

Both hands move continuously at a constant speed. Write a program that converts Tim's phrases into ordinary times.

Input

The first line has the number of test cases nn. Each of the next nn lines holds one string of the form a after b or a til b, where aa and bb are integers with 0a<3600 \le a < 360 and 1b121 \le b \le 12.

The angle is measured starting at the hour hand and moving clockwise until reaching the minute hand. At 9 o'clock the hands make an angle of 90 degrees, and at 3 o'clock they make an angle of 270 degrees.

after means only a time later than bb o'clock, and til means only a time earlier than bb o'clock. If the angle is already aa degrees at bb o'clock, that exact moment is not an answer.

Output

For each test case print one line of the form Case i: h:m:s, where ii is the test case number starting at 1, and hh, mm and ss are the hour, the minute and the second closest to the time you found.

The hour satisfies 1h121 \le h \le 12 and is printed without padding. Always print two digits for the minute and two digits for the second.