Problem E
Peter Takes a Tramway
Input: standard input
Output: standard output
Time Limit: 2 seconds


Main Town has a well-developed system of tramway network. Since most of the important buildings in town are located along the Main Street, almost all the tramways pass through the street. All the stops along the Main Street, and there are very many of them, are numbered with numbers: 0, 1, 2 and so on. All the tramways enter the Main Street at the stop numbered 0 and continue towards the higher numbered stops. For each tramway line, which is identified also by a number, there is a schedule posted at stop 0 giving the minutes within an hour when a tramway of this line leaves the stop.

Peter arrives at stop 0 at m minutes (0 <= m < 60) after an hour and takes the first tramway that leaves stop 0 along the Main Street. If Peter arrives at stop 0 the same minute when a tram leaves, Peter manages to board the tram. He leaves the tram at the next stop and takes the next tram that arrives and continues to the next stop where he leaves. Peter continues in this fashion until he reaches stop 0 < n < 1000000000. By which tram will Peter arrive at stop n?


Input contains multiple cases. The first line of a case gives t, the number of tramway lines, 0<t<30. The next t lines each contain a number of a tram line followed by a colon and then a list (separated by spaces) of minutes after a full hour when the tram of this line leaves stop 0. Each list of departure times is terminated by -1. No tram leaves stop 0 more than 20 times in an hour, no two trams leave station 0 at the same time, all the trams have the same speed and they never meet at a stop. A line with m and n then follows. The input ends with a line where t= 0. This line should not be processed.


For each case of input, output in a format shown below the number of the tram line by which Peter arrives at stop n.


Sample Input
11: 10 20 30 -1
3 2
11: 10 20 30 -1
134: 16 25 35 45 58 -1
48 783




Sample Output
Case 1: Peter arrives at stop 2 by tram 11.
Case 2: Peter arrives at stop 783 by tram 134.

(Problem-setters: Piotr Rudnicki, University of Alberta, Canada) 



“If the educational system of an institute is based on mere memorization

and directionless class notes then it surely will struggle to

arrange a proper programming contest.”