You are given a rooted tree consisting of $$$n$$$ vertices, numbered from $$$1$$$ to $$$n$$$. Vertex $$$1$$$ is the root.
Each vertex $$$v$$$ initially stores a function
$$$$$$ f_v(x) = a_v x + b_v, $$$$$$
where $$$a_v$$$ and $$$b_v$$$ are positive integers.
You have to perform the following operation exactly $$$n-1$$$ times until only the root vertex remains:
After $$$n-1$$$ operations, only vertex $$$1$$$ remains with a final function $$$F(x)$$$. Your task is to maximize the value of $$$F(0)$$$.
The first line contains an integer $$$t$$$ $$$(1 \le t \le 100)$$$ — the number of test cases.
For each test case:
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$, and the edges form a valid rooted tree with root $$$1$$$.
For each test case, print a single integer — the maximum possible value of $$$F(0)$$$.
It is guaranteed that, for all inputs, the maximum possible value of $$$F(0)$$$ fits in a signed 64-bit integer.
231 54 22 31 21 352 12 33 12 24 11 21 32 42 5
54148
In the first test case, the root is $$$1$$$ with $$$f_1(x) = x + 5$$$.
Its children are $$$2$$$ [$$$f_2(x) = 4x + 2$$$] and $$$3$$$ [$$$f_3(x) = 2x + 3$$$].
In the second test case, one optimal deletion order is $$$4, 5, 2, 3$$$. The final function is $$$96x + 148$$$, so the answer is $$$148$$$.
| Название |
|---|


