Tree Product
Time limit2sMemory limit256 MB
Given n rooted trees, find the orderings of their tree product that give the maximum and the minimum diameter.
Problem
Given rooted trees , find two permutations and such that the diameter of is maximum and the diameter of is minimum.
For two rooted trees and , their tree product is defined as follows: copy tree , and then for each vertex in it, make a copy of and merge its root with vertex . See the table below for an example:

It can be shown that tree product is associative: . So the parentheses in a product of three or more trees can be omitted.
Recall that:
- A tree is a connected graph without cycles. A rooted tree has a special vertex called the root. The parent of a vertex is the last vertex different from on the path from the root to .
- The diameter of a rooted tree is the length of the longest simple path in the tree, where the length of a path is the number of edges in the path.
Input
There are multiple test cases. The first line of input contains an integer , indicating the number of test cases. For each test case:
The first line contains an integer , indicating the number of rooted trees.
Each of the next lines starts from an integer (), indicating the number of vertices in the -th rooted tree. It is followed by integers () on the same line, where the -th of them denotes the parent of the -th vertex. The root of the tree has as parent.
It is guaranteed that the sum of over all test cases does not exceed .
Output
For each test case, output two integers: the maximum and the minimum diameter, in that order.
Hint
For the first sample test case, will provide the maximum diameter, while will provide the minimum diameter.