Given a tree with N nodes, and two integers A and B.
Every node has a magic value Mi (1<=i<=N) associated with it.
Consider Node 1 as root of the tree.
There are Q queries of type -
- X U V , where you have to find the number of nodes Y in the subtree of node X such that -
- A <= Distance ( X, Y ) <= B
- U <= Magic value of Y <= V
Note : Distance ( X, Y ) - Number of edges in path from X to Y.
Input Format
First line contain three integers N,A,B, number of nodes and A,B .
Next line contains N integers, Mi magic value of each Node from 1 to N.
Next line contains N-1 space separated integers, Pi parent of each Node from 2 to N .
Next line contain Q, number of queries.
Next Q lines contains queries of type as mentioned above.
Output Format
Answer corresponding to each query in a single line .
Constraints
1<= N, Mi, Q, A, B, U, V <= 10^5,
1<= Pi < i