#P7805. Imperative Meeting
Imperative Meeting
Imperative Meeting
Problem Description
Some rumors about Zhang3 have been spread on the Internet. Zhang3 needs to dispel the rumors, but she's busy preparing her birthday party, so she asks her classmates for help. Her classmates decide to have a meeting for discussion. The classmates live in the same community. There are houses in the community, labeled . There are roads connecting the houses, the of which connects house and , forming a tree. Each road is 1 km long. The classmates live in different houses. They always choose such a house to have the meeting, that the total distance to travel for the classmates is minimized. The optimal total distance (in km) to travel is called the cost of the meeting. Zhang3 doesn't know which houses her classmates live in, so there are different cases of that. Zhang3 wants to know the sum of the cost in all cases. As the answer can be very large, please help her calculate the answer modulo .
Input
The first line of the input gives the number of test cases, . test cases follow. For each test case, the first line contains two integers , the number of houses in the community and the number of classmates. The second line contains integers , separated by spaces, describing the roads. The sum of in all test cases doesn't exceed .
Output
For each test case, print a line with an integer, representing the answer modulo .
Sample Input
2
4 3
1 1 1
5 3
1 2 3 3
Sample Output
9
27
Source
2020 Multi-University Training Contest 4