There is a company that is very famous for arranging unfair contests. They are arranging a new weird contest.
The contest is about guessing a number. The company will call it the magic number. The magic number for the contest is yet to be decided by the company.
The contest consists of an infinite number of rounds. In each round, every participant will guess a number and submit it to the judge. If at least one of the submissions of that particular round contains the magic number, the contest ends. Then the winner of the contest will be the contestant who guessed it correctly in that particular round. If there are several contestants who have guessed it correctly, then the contestant with the lowest index will be the winner.
There are participants indexed from to . To make the contest unfair, the surveillance team of the company has collected three attributes of the strategy of each contestant, .
It means contestant will choose as the guess for the round as long as the guess is less than or equal to . If the guess exceeds then the contestant will quit the contest.
Moreover, the team discovered a pattern in the strategies of the contestants, that is, is always divisible by .
The CEO of the company is very determined to make the contest unfair. So, he will ask queries. Note that, each query is independent.
In each query, he will choose a magic number and he is eager to know who will be the winner if he chooses it for the contest. As his helping hand, determine the winner for that specific magic number or say there will be no winner.
The first line of input contains two space-separated integers, and , the number of contestants and the number of queries, respectively.
Each of the next lines contains three space-separated integers, and , three attributes for the contestant.
Each of the next lines contains a single integer , the magic number for the query.
For each query, if there is no winner, print , otherwise, print the index of the winner.
Input | Output |
---|---|
3 3 4 6 2 3 9 3 2 6 2 2 3 6 | 3 2 1 |