A magical tree with N vertices and N−1 edges is provided to you. Each of the N−1 edges have some positive weight. Assuming there are X edges in the simple path between vertices A and B, then the separation between the vertices A and B can be determined using the following formula:
Now, the mystical value for each vertex is defined as the sum of the separation between this vertex & every other vertex. Your task is to determine the minimum mystical value that a vertex has in the given magical tree.
Note: A simple path is a path in a tree that does not have repeating vertices.
Input format
Output format
For each test case, print the minimum mystical value that a vertex has in the given magical tree in a new line.
Constraints
1≤T≤1053≤N≤1061≤u,v≤N1≤w≤106The sum of all values of N over all test cases doesn't exceed 106
The first line denotes T = 1.
For test case 1:
We are given:
Now,
Since the minimum mystical value that a vertex has in the given magical tree is 19, the answer to this test case is 19.