Time limit
2s
Memory limit
128 MB
At World Company, an employee who has worked for a long time can be promoted and receive a higher salary.
For an employee, a supervisor is an employee who earns more and has worked at least as long. Among all such employees, the direct supervisor is the one with the smallest salary.
For a direct supervisor, that employee is a direct subordinate. Direct subordinates and all subordinates below them are counted as that supervisor's subordinates. An employee who is not anyone's supervisor has no subordinates.
Using this rule for supervisor-subordinate relationships, answer each query with the employee's direct supervisor ID and total number of subordinates.
The first line contains two integers n (1 ≤ n ≤ 30,000) and m (1 ≤ m ≤ 200), where n is the number of employees and m is the number of queried employees.
Each of the next n lines contains three integers a, b, and c. Here a (1 ≤ a ≤ 2,147,483,647) is the employee ID, b (0 ≤ b ≤ 10,000,000) is the salary, and c (1,000,000 ≤ c ≤ 2,500,000) is the work time in minutes. Employee IDs are distinct.
Each of the next m lines contains the ID of one queried employee. Every queried ID appears among the employee records.
For each queried employee, in the same order as the input, print one line containing the direct supervisor's ID and the total number of subordinates, separated by a space.
If the queried employee is the top employee, meaning the employee with both the longest work time and the highest salary, print 0 instead of a direct supervisor ID.