eolymp
bolt
Try our new interface for solving problems
Problems

Cube Painting

Cube Painting

prb89 Sara was presented with a new Lego-like game as her birthday gift. This game, Unbounded Imaginations (UI), contains lots of uniform cubes such that each side of these cubes has an area of 1 cm^2. The special attribute of UI is that someone can fix two cubes, side by side, with special glue such that two mentioned sides fit each other exactly. Dara as her big brother has decided to design a problem for Sara using UI. He constructs a 3D object by using these cubes and wants Sara to paint every side which is not coupled. We say a side is not coupled if it is not connected to another cube. For example imagine the object is something like this:

In the above example, sum of all not coupled sides is 16. The problem is to find out this number which shows how much area Sara should paint.

Input

The first line contains the number of test cases. Each test case starts with the number of cubes n (1n200). Cubes are numbered from 1 to n.

Next n lines describe the formation of the objects: connection data are given for each cube in one line. Each of these lines starts with an integer I, which is a cube number, followed by a colon character ":" and a blank, followed by some integers (at most six) which are the cubes connected to I, and finally followed by a single zero character "0" indicating the end of set. It is guaranteed that data for each test case realizes a valid object in space. Note that cubes can construct any complex object or even multiple small separated objects.

Output

For each test case print on a separate line the sum of not coupled sides for all cubes.

Time limit 1 second
Memory limit 128 MiB
Input example #1
3
4
1: 2 3 0
2: 1 4 0
3: 4 1 0
4: 2 3 0
3
1: 2 0
2: 3 1 0
3: 2 0
4
1: 2 0
2: 1 0
3: 4 0
4: 3 0
Output example #1
16
14
20