SP17443 MABJ - Magical Bus Journey

Description

Townsville has a well developed bus system. Since most of the important buildings in town are located along the Main Street, almost all the buses 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 buses enter the Main Street at the stop numbered 0 and continue towards the higher numbered stops. For each bus line (which is also identified by a number), there is a schedule posted at stop 0 giving the minutes within an hour when a bus of this line leaves the stop. Rahul arrives at stop 0 at m minutes (0

Input Format

Input contains multiple cases. The first line of a case gives t, the number of bus lines, 0 < t < 30. The next t lines each contain a number of a bus line followed by a colon and then a list (separated by spaces) of minutes after a full hour when the bus of this line leaves stop 0. Each list of departure times is terminated by -1. No bus leaves stop 0 more than 20 times in an hour, no two buses leave station 0 at the same time, all the buses 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.

Output Format

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