SP1487 PT07J - Query on a tree III

Description

You are given a node-labeled rooted tree with _n_ nodes. Define the query (_x_, _k_): Find the node whose label is _k_-th largest in the subtree of the node _x_. Assume no two nodes have the same labels.

Input Format

The first line contains one integer _n_ (1

Output Format

For each query (_x_, _k_), output the index of the node whose label is the _k_-th largest in the subtree of the node _x_.