TreeScript

아직 제출이 없습니다시간 제한1초메모리 제한1024 MB

문제

TreeScript is a programming language developed for maintaining tree structures. In this problem, we will learn how to create rooted trees in TreeScript.

In TreeScript, all tree nodes are stored in memory. Each tree node has a number and the address of its parent node, and both are immutable, so they have to be determined when creating the node. In particular, the address of the root node's parent node is empty.

In order to access these nodes, the address of a node can be stored in a register. If there are mm registers, the registers can be written as r\[0],r\[1],,r\[m1]r\[0],r\[1],\ldots ,r\[m-1].

Now let's learn the node creation statement: r\[i]=create(r\[j],k);r\[i]=\mathrm{create}(r\[j], k); where kk is the node number, ii and jj are the indices of the registers, where 0i,j<m0\le i,j< m and i=ji=j is possible. The effect of this statement is that a node numbered kk is created, whose parent address is stored in r\[j]r\[j], and then the new node's address is stored in r\[i]r\[i]. Once each node has been created correctly, you do not need to store the address of any more nodes; they will automatically execute the pre-defined instructions. For reasons of space, we will learn about them later.

To check your learning, you need to create a rooted tree of size nn. At first, the system will automatically create the root node for you and store it in r\[0]r\[0]. So you only need to execute n1n-1 additional creation instructions to create the tree.

As you know, registers are very expensive, so you need to find the minimum amount mm of the registers you need.

입력

There are multiple test cases.

The first line of the input contains one integer TT (1T1051\le T\le 10^5) --- the number of test cases.

For each test case:

The first line contains one integer nn (2n21052\le n\le 2\cdot 10^5) --- the size of the tree.

The second line contains nn integers p_1,p_2,,p_np\_1,p\_2,\ldots,p\_n, where node p_ip\_i is the parent node of node ii and 1p_i\<i1\le p\_i\<i. Specially, p_1=0p\_1=0 and it means 11 is the root of the tree.

The sum of nn over all test cases does not exceed 2×1052\times 10^5.

출력

For each test case, output the answer in one line.