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 species are numbered with integers between 1 and , inclusive. Species 1 has no direct ancestor, and all other species have exactly one direct ancestor each, from which they directly evolved. A (not necessarily direct) ancestor of species is any other species such that can be reached from by moving one or more times to a species direct ancestor starting from . In this way, species 1 is a (direct or indirect) ancestor of every other species.
Through complex genetic simulations, she calculated the average score each of the species would get in a particular coding competition. is that average score for species .
Ada is looking for interesting triplets to showcase in her presentation. An interesting triplet is defined as an ordered triplet of distinct species such that:
Species is a (direct or indirect) ancestor of species .
Species is not a (direct or indirect) ancestor of species .
Species has an average score strictly more than times higher than both of those of and . That is, .
Given the species scores and ancestry relationships, help Ada by writing a program to count the total number of interesting triplets.
输入格式
The first line of the input gives the number of test cases, . test cases follow.
The first line of each test case contains two integers and , denoting the number of species and the factor which determines interesting triplets, respectively.
The second line of each test case contains integers , where denotes the average score of species .
The third line of each test case contains integers , meaning species is the direct ancestor of species .
输出格式
For each test case, output one line containing case #x: y, where is the test case number (starting from 1) and is the total number of interesting triplets according to Ada's definition.