Problems
Ada is working on a science project for school. She is studying evolution and she would like to compare how different species of organisms would perform when trying to solve a coding competition problem.
The
Through complex genetic simulations, she calculated the average score each of the
Ada is looking for interesting triplets to showcase in her presentation. An interesting
triplet is defined as an ordered triplet of distinct species
- Species
b is a (direct or indirect) ancestor of speciesa . - Species
b is not a (direct or indirect) ancestor of speciesc . -
Species
b has an average score strictly more than\mathbf{K} times higher than both of those ofa andc . That is,\mathbf{S_b} \ge \mathbf{K} \times \max(\mathbf{S_a}, \mathbf{S_c}) + 1 .
Given the species scores and ancestry relationships, help Ada by writing a program to count the total number of interesting triplets.
Input
The first line of the input gives the number of test cases,
The first line of each test case contains two integers
The second line of each test case contains
The third line of each test case contains
Output
For each test case, output one line containing
Case #, where
Example
2
5 2
3 3 6 2 2
3 1 1 3
7 3
2 4 7 2 2 1 8
6 1 7 3 1 3
Case #1: 1
Case #2: 7