#P1062E. Company
Company
No submission language available for this problem.
Description
The company has employees numbered from through . Each employee has a direct boss (), except for the employee who has no boss. It is guaranteed, that values form a tree. Employee is said to be in charge of employee if is the direct boss of or there is an employee such that is in charge of and is the direct boss of . Also, any employee is considered to be in charge of himself.
In addition, for each employee we define it's level as follow:
- for
In the near future, there are possible plans for the company to operate. The -th plan consists of two integers and , meaning that all the employees in the range , and only they, are involved in this plan. To operate the plan smoothly, there must be a project manager who is an employee in charge of all the involved employees. To be precise, if an employee is chosen as the project manager for the -th plan then for every employee , must be in charge of . Note, that is not necessary in the range . Also, is always chosen in such a way that is as large as possible (the higher the level is, the lower the salary that the company has to pay the employee).
Before any plan is operated, the company has JATC take a look at their plans. After a glance, he tells the company that for every plan, it's possible to reduce the number of the involved employees exactly by one without affecting the plan. Being greedy, the company asks JATC which employee they should kick out of the plan so that the level of the project manager required is as large as possible. JATC has already figured out the answer and challenges you to do the same.
The first line contains two integers and (, ) — the number of employees and the number of plans, respectively.
The second line contains integers () meaning is the direct boss of employee .
It is guaranteed, that values form a directed tree with the root of .
Each of the following lines contains two integers and () — the range of the employees, involved in the corresponding plan.
Print lines, each containing two integers — the number of the employee which should be kicked from the corresponding plan and the maximum possible level of the project manager in that case.
If there are more than one way to choose that employee, print any of them.
Input
The first line contains two integers and (, ) — the number of employees and the number of plans, respectively.
The second line contains integers () meaning is the direct boss of employee .
It is guaranteed, that values form a directed tree with the root of .
Each of the following lines contains two integers and () — the range of the employees, involved in the corresponding plan.
Output
Print lines, each containing two integers — the number of the employee which should be kicked from the corresponding plan and the maximum possible level of the project manager in that case.
If there are more than one way to choose that employee, print any of them.
Samples
Note
In the example:

In the second query, if we choose any employee other than the employee , the project manager will be . If we choose , the project manager will be . Since , choosing is the best strategy.
In the third query, no matter how we choose the employee, the project manager will always be .
In the fourth query, if we choose or then the project manager will be . If we choose then the project manager will be . Since , we choose as the answer.