Given a rooted tree with $n$ nodes, where node 1 is the root and the parent of node $i$ ($2 \le i \le n$) is node $p_i$.
For $1 \le i \le n$, define the depth $d_i$ of node $i$ as the number of edges on the simple path from node 1 to node $i$. That is, $d_1 = 0$ and $d_i = d_{p_i} + 1$ ($2 \le i \le n$). Define the height $h$ of the rooted tree as the maximum depth of all nodes, i.e., $h = \max_{i=1}^n d_i$.
Given an upper bound $m$ on the height. In this problem, the height of the given rooted tree does not exceed $m$.
You need to assign a non-negative integer as the weight to each node. For $1 \le i \le n$, if the weight of node $i$ is $a_i$, let $S_i$ denote the set of weights of all nodes in the subtree of node $i$. For each weight assignment scheme, define the value of the tree as $\sum_{i=1}^n \text{mex}(S_i)$, where $\text{mex}(S)$ denotes the smallest non-negative integer not present in the set $S$. For example, in the figure below, if we set $a_1 = 3, a_2 = 2, a_3 = a_4 = 0, a_5 = 1$, then $S_1 = \{0, 1, 2, 3\}, S_2 = \{0, 1, 2\}, S_3 = \{0\}, S_4 = \{0\}, S_5 = \{1\}$, and the value of the tree is $4 + 3 + 1 + 1 + 0 = 9$.
You need to find the maximum value of the tree among all possible weight assignment schemes.
Input
The first line contains a positive integer $t$, representing the number of test cases.
For each test case: The first line contains two positive integers $n, m$, representing the number of nodes and the upper bound of the height, respectively. The second line contains $n - 1$ positive integers $p_2, p_3, \dots, p_n$, representing the parent of each node.
Output
For each test case, output a single line containing a non-negative integer, representing the maximum value of the tree.
Examples
Input 1
2 5 2 1 1 2 2 7 2 1 1 2 2 2 3
Output 1
9 13
Note
For the first test case, we can set $a_1 = 3, a_2 = 2, a_3 = a_4 = 0, a_5 = 1$, then the value of the tree is $4 + 3 + 1 + 1 + 0 = 9$. For the second test case, we can set $a_1 = 4, a_2 = 3, a_4 = 2, a_3 = a_6 = 1, a_5 = a_7 = 0$, then the value of the tree is $5 + 4 + 2 + 0 + 1 + 0 + 1 = 13$.
Input 2
(See tree/tree2.in)
Output 2
(See tree/tree2.ans)
Note
This example satisfies the constraints for test cases 3 and 4.
Input 3
(See tree/tree3.in)
Output 3
(See tree/tree3.ans)
Note
This example satisfies the constraints for test cases 7 and 8.
Input 4
(See tree/tree4.in)
Output 4
(See tree/tree4.ans)
Note
This example satisfies the constraints for test cases 13 and 14.
Input 5
(See tree/tree5.in)
Output 5
(See tree/tree5.ans)
Note
This example satisfies the constraints for test cases 18 and 19.
Constraints
For all test cases: $1 \le t \le 5$; $2 \le n \le 8,000$, $1 \le m \le \min(n - 1, 800)$; For all $2 \le i \le n$, $1 \le p_i \le i - 1$; The height of the given rooted tree does not exceed $m$.
| Test Case ID | $n \le$ | $m \le$ |
|---|---|---|
| 1, 2 | 7 | $n - 1$ |
| 3, 4 | 13 | $n - 1$ |
| 5, 6 | 18 | $n - 1$ |
| 7, 8 | 40 | $n - 1$ |
| 9, 10 | 120 | $n - 1$ |
| 11, 12 | 360 | $n - 1$ |
| 13, 14 | 4,000 | 2 |
| 15 ~ 17 | 4,000 | 10 |
| 18, 19 | 4,000 | 50 |
| 20 ~ 25 | 8,000 | 800 |