You are given a tree of $$$n$$$ nodes, where node $$$i$$$ has weight $$$w_i$$$, and an integer $$$k$$$.
Let the tree be rooted at node $$$x$$$. You may select a subset $$$S$$$ of the nodes such that $$$|S| = k$$$ and $$$x \in S$$$. Let $$$f(i)$$$ be the sum of the weights of all nodes in $$$S$$$ on the path from node $$$i$$$ to the root. The score of $$$S$$$ is $$$\sum_{i \in S} f(i)$$$.
For each node $$$1 \le x \le n$$$, find the maximum possible score among all subsets $$$S$$$ if the tree is rooted at node $$$x$$$.
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 500$$$). The description of the test cases follows.
The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$2 \le n \le 4000$$$, $$$1 \le k \le n$$$).
The second line of each test case contains $$$n$$$ integers $$$w_1, w_2,\ldots, w_n$$$ ($$$1 \le w_i \le 10^9$$$).
Each of the next $$$n - 1$$$ lines contains two integers $$$u$$$ and $$$v$$$ ($$$1 \le u, v \le n$$$), indicating that nodes $$$u$$$ and $$$v$$$ are connected by an edge. It is guaranteed that the given graph is a tree.
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$4000$$$.
For each test case, print $$$n$$$ integers. For each $$$x$$$ from $$$1$$$ to $$$n$$$, print the maximum possible score among all subsets $$$S$$$ if the tree is rooted at node $$$x$$$.
36 32 12 3 6 9 71 21 33 44 54 65 510000 1000 100 10 11 22 33 43 59 57 11 5 16 13 10 12 9 158 11 63 74 66 76 59 12 8
27 57 30 39 51 4554311 15311 12511 12451 12415120 150 134 170 155 122 150 132 162
In the first test case, the tree is as follows:
For each $$$1 \le x \le n$$$, the following is an optimal set $$$S$$$:
In the second test case, $$$S = \{1, 2, 3, 4, 5\}$$$ for all $$$x$$$.
| Name |
|---|


