An Old Stone Game

No attempts yetTime limit1sMemory limit128 MB

Problem

There is an old stone game played on an arbitrary general tree TT. The goal is to place a single stone on the root of TT while obeying the following rules:

  1. At the start of the game, the player picks KK stones and puts them all into one bucket.
  2. At each step, the player may take one stone from the bucket and place it on any empty leaf.
  3. When every one of the rr immediate children of a node pp holds one stone, the player may remove all rr of these stones and place one of them on pp. The remaining r1r-1 stones are returned to the bucket and can be reused in later steps.

The player wins if, by following these rules, a stone is successfully placed on the root of the tree.

Write a program that determines the least number of stones KK the player must pick at the beginning so that the game on the given tree can be won.

Input

The input describes several trees. The first line contains MM, the number of trees (1M101 \le M \le 10). Descriptions of the MM trees follow. Each tree has N<200N < 200 nodes labeled 1,2,,N1, 2, \dots, N, and each node may have any number of children. The root is labeled 11. Each tree's description begins with NN on its own line. The next NN lines describe the children of every node in order of their labels; each line contains a node label pp (1pN1 \le p \le N), the number rr of immediate children of pp, and then the labels of those rr children.

Output

For each input tree, print one line containing the minimum number of stones that must be picked in rule 1 in order to win the game on that tree.