Indra is stuck! Surrounded, with no escape from the certain death he will face in the coming moments. His only option - fight for his life! Now, you're probably wondering how he got into this situation...
You see, a few weeks prior Indra was implementing a goblin tree, but the final step befuddled him: how are you meant to burn a sacrificial lamb in the middle of a coding contest? Feeling insulted by Indra's obvious disrespect in skipping the crucial step, the code goblins transported him to the goblin dimension to spend the rest of his days.
The heirarchy of the goblin kingdom in the goblin dimension is like so: There is a king goblin (goblin 0), and every goblin who is not the king has a superior. Furthermore, Goblins (as well as Indra) have power ratings. Indra cosplays as a goblin and infiltrates their ranks.
As Indra's fairy godmother, you do not know which goblin he is, but you do worry about him - therefore, you must answer queries of the form "If Indra is goblin x, how many of his direct superiors could he defeat in battle?". First Indra defeats his supervisor, then his supervisor's supervisor, and so on while the sum of their power ratings is less than or equal to his.
Input Format
The first line of the input consists of three integers, . These represent the number of goblins, the number of queries, and Indra's power rating. The next lines each contain one integer, representing the power rating of that goblin.
The next lines will consist of two space-separated integers , meaning that goblin and is the superior of goblin .
Finally, the next lines each consist of an integer , representing a query for if Indra is goblin .
Output Format
For each of the queries, output a single integer on its own line: the number of goblins above him that he could beat in battle.
Example Input
4 1 10
5
5
5
5
0 1
1 2
2 3
3
Example Output
2
Example Explanation
The answer is as if Indra is goblin then he can defeat and .
Comments