Bob wants to know about his ancestors, therefore, he draws a graph of his family. In that graph, root is the eldest-known family member. The leaf node is a member who has no children.
You are given a \(Q\) query and \(N\) family members. They have to just print the \(k^{th}\) ancestors with respect to that query. A member can have only one parent.
Note: Print -1 if the query is incorrect, that is, if the \(k^{th}\) ancestor is not available. The root of the tree is 1.
Input format
Output format
For each query, print a single line containing one integer.
Constraints
\(1 ≤ N,\ Q ≤ 5e5\\ 0 ≤ k ≤ 5e5\)
In this tree 1st Parent of 4th node is 3 and also 3rd parent is node 1.
For Third Query 1st parent of 6 is root node.