A data stream is a real-time, continuous, ordered sequence of items. Examples include sensor data, Internet traffic, financial tickers, online auctions, and transaction logs such as web usage logs and telephone call records. Queries over streams also run continuously over a period of time and incrementally return new results as new data arrives. For example, a temperature-monitoring system in a factory warehouse might run queries such as:
Argus is a Data Stream Management System that processes such queries over data streams. Users register queries with Argus, and Argus keeps them running over the changing data, returning results to each user at the requested frequency.
A query is registered with the following instruction:
Register Q_num Period
Q_num (0 < Q_num <= 3000) is the query ID number, and Period (0 < Period <= 3000) is the interval in seconds between two consecutive result returns. The first result is returned Period seconds after registration, and after that a result is returned every Period seconds.
Several queries are registered with Argus at the same moment. All queries have distinct Q_num values. Your task is to report the first K queries to return a result. If two or more queries return a result at the same time, they do so one at a time in ascending order of Q_num.
The first part of the input lists the register instructions given to Argus, one instruction per line. There are at most 1000 instructions, and all of them are executed at the same time (time 0). This part ends with a line containing a single #.
The second part is a single line containing one positive integer K (K <= 10000).
Output the Q_num of the first K queries to return a result, one number per line.