He Who Must Not Be Named, Lord Voldemort, is chasing Harry and Hermione. They have been able to reach the train station but, He Who Must Not Be Late, Ron, is running late. Now, Harry goes to the counter to ask about the tickets available later today. The man behind the counter gives Harry some rather "Riddikulus" information:
In this world, the whole day is only 2H hours and the hour hand rotates 360 degrees every H hours (Similar to our world of 24 hours and the hour hand rotates 360 degrees every 12 hours). The first H hours is called AM and the second H hours of the day is called PM.
Each H is made up of M minutes.
Trains are only available, exactly when the hour hand and minute hand overlap. Train for a day starts at 00:00 AM.
Now Harry wants to know how long he has to wait before the next trains (all possible ones) arrive today.
The input consists of T test cases.
Each test case contains 4 integers H, M, CurrentHour and CurrentMinute and a string "AM" or "PM". CurrentHour and CurrentMinute refer to the time Harry asked about trains in the counter (The time took for the man to provide Harry all the information is negligible).
Print the case number and x, the number of upcoming trains today. The next x lines will contain the time Harry has to wait if he and Hermione want to catch that train, in hours and minutes (look in the sample test cases for clarification). Round the result to the nearest case if it has a decimal in it.
2 12 60 10 15 AM 12 60 4 15 PM
Case 1: 12 0h 40m 1h 45m 2h 50m 3h 56m 5h 1m 6h 7m 7h 12m 8h 18m 9h 23m 10h 29m 11h 34m 12h 40m Case 2: 7 0h 7m 1h 12m 2h 18m 3h 23m 4h 29m 5h 34m 6h 40m