시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 128 MB0000.000%

문제

Well renowned internet-based company ACM (Analog Computing Machinery) constructed a human network among employees to broadcast emergency messages from the chief executive officer (CEO) of the company. The emergency message from the CEO should be transmitted to all employees through the human network. The network is structured as a rooted tree where an employee of the company corresponds to one node of the tree and the CEO of the company corresponds to the root node. Initially the CEO, the root node, makes an emergency message. In a single round of time, any node that knows the emergency message can send the message to at most one of its children. We are going to compute the minimum number of rounds of time for the message from the CEO to be delivered to all employees of the company.

For example, the minim number of round is 5 when the rooted tree is structured as in Figure 1. Each directed edge in Figure 1 denotes a delivery of a message from one employee to another. Nodes marked with • denote employee who received the emergency message from the CEO of the company, including the CEO himself or herself.


Figure 1. An emergency message from the root node being broadcasted through a rooted tree in five rounds.

Given a rooted tree structure, write a program to compute the minimum number of rounds of time required for the emergency message from the root node of the tree to be delivered to all nodes.

입력

Your program is to read from standard input. The input consists of T test cases. The number of test cases T is given in the first line of the input. The first line of each test case contains an integer n (1 ≤ n ≤ 5,000) which is the number of nodes in the rooted tree. Each node is numbered from 1 to n, where 1 is assigned to the root node. The following n lines for each test case contain a list of child nodes for a node. In each line there are at least two numbers m k c1 c2 … ck (1 ≤ m ≤ n , 0 ≤ k ≤ n), where m denotes some node in the tree, k denotes the number of child nodes of the node numbered m, and c1 c2 … ck is the k child nodes of the node m. 

출력

Your program is to write to standard output. Print exactly one line for each test case. The line should contain the minimum number of rounds required to broadcast the emergency message from the root node to all nodes.

예제 입력 1

3
13
1 3 2 7 8
2 2 3 4
3 2 5 6
4 0
5 0
6 0
7 2 9 10
9 0
10 2 12 13
12 0
13 0
8 1 11
11 0
5
1 4 2 3 4 5
2 0
3 0
4 0
5 0
4
1 1 2
2 1 3
3 1 4
4 0

예제 출력 1

5
4
3