There is a large tree house in an unknown world. It is ruled by the great emperor KZS. It consists of nodes numbered from to in which the people of that world reside. The nodes are organized in a tree structure rooted at node . You need to assign values to the nodes according to the wishes of emperor KZS which are as follows :-
- The value of node is .
- All immediate children of any node have pairwise distinct values.
- For every node with at least one immediate child, the of the values of all immediate children is equal to the value of the node.
- The total sum of the values of all nodes should be minimum.
The greatest common divisor of two positive integers and is equal to the largest integer such that both integers and are divisible by .
Print the sum of all values, modulo .
Input
- The first line contains an integer , the number of test cases. testcases follow.
- The first line of each test contains two integers and .
- Each of the following lines contains two integers and , denoting an edge between nodes and .
Output
- For each test case, print the sum of values, modulo .
Constraints
- and
- The given edges form a tree
- The sum of over all test cases doesn't exceed .
Subtasks
Subtask #1 (100 points): Original Constraints
Sample Input
2
4 1
1 2
1 3
1 4
8 1
1 2
1 3
2 4
2 5
5 6
5 7
7 8
Sample Output
7
11
Explanation
In test case , we will give values , , to the nodes , and respectively. So, the total sum will be .
Condition For the Solution : Follow All our social Media Account, We are New. After getting enough Subscriber we will start Uploading the Solution without any Condition, Please Understand...
Website :- https://codedelhi.blogspot.com Telegram :- https://t.me/EngineerDelhi Facebook :- https://www.facebook.com/EngineerDelhi Instagram :- https://www.instagram.com/engineerdelhi
DM all the Screen Shots on Telegram, we will send the solution there, due to Community Guidelines of Codechef. We can not share here....