Returning to Moldova, Alexandru Lăpușneanu wants to take revenge on the boyars in a draconic manner, and the only way they can escape the wrath of the ruler is by solving the following problem:
Task
Given a tree with nodes rooted at node , each node having an associated value . There are queries of the form: (), which ask how many nodes in the subtree of node have values between and (inclusive).
Input data
The first line contains the natural number . The second line contains natural numbers - the values associated with the nodes. The next lines contain two natural numbers and , indicating that there is an edge in the tree between nodes and . The next line contains the natural number , representing the number of queries. The next lines contain three natural numbers as described in the statement.
Output data
The output will consist of lines, where the -th line contains the answer to the -th query.
Constraints and clarifications
- for
- For tests worth points, and
- Additional tests were added after the contest
Example
stdin
5
10 17 10 19 4
2 1
1 3
2 4
2 5
3
2 6 19
1 11 17
1 4 19
stdout
2
1
5