1026: SYH’s Easy Tree Problem

Memory Limit:256 MB Time Limit:4.000 S
Judge Style:Text Compare Creator:
Submit:7 Solved:2

Description

SYH loves researching an interesting but easy data structure --- Tree. Assume there are n nodes on the tree. SYH paints all the nodes on the tree with color ci firstly. Then, he will ask you q questions in the form of xi and ki: How many colors of nodes are no less than ki in the sub-tree of the node xi.

Input

The first line conatins an integer T, means the number of test cases. For each test case, the first line contains two integers n and q. The second line contains n integers describing c1~cn. Then, n-1 lines contain two integers ai, bi in each, expressing the tree, while there is a path connecting ai and bi with one another. Then q lines contain two integers xi, ki in each, meaning the questions.

Output

For each test case ouput “Case: #x:” in a single line. x is the test case number (starting from 1). Then q lines of the following answer.

Sample Input Copy

1

8 4
1 3 1 8 8 3 1 8
1 2
1 6
5 6
8 6
2 3
4 2
2 7
2 2
6 3
1 3
2 1

Sample Output Copy

Case #1: 
1
0
2
3

HINT

For the first sample, let color-1 is red, color-3 is yellow, color-8 is green.

The tree is showed below:


For the first question, only red satisfies.

For the second question, no color of nodes exsists no less than 3.

For the third question, red and green both satisfy.

For the fourth quesion, red, yellow and green all staisfy.



T = 1, 1 ≤ n, q, ci, ki ≤ 105, 1 ≤ ai, bi, xi ≤ n.