beecrowd | 1368

# Colorful Cubes

By Ricardo Anido Brazil

Timelimit: 1

Kids love to play with little cubes. They spent hours creating 'houses', 'buildings', etc. Tomaz's little brother just won a set of colorful cubes on his birthday. Each face of each cube has a different color.

As Tomaz is a very analytic kid, he decided to find out how many "kinds" of different cubes his little brother won. Can you help him? Two cubes are considered the same kind if it's possible to rotate one of them in a way that the colors at the respective faces of the cubes are equals.

## Input

The input contains several test cases. The first line of a test case contain an integer N specifying the number of cubes of the set (1 ≤ N ≤ 1000). The next 3 x N lines describe a set of cubes. In the description the colors will be identified by the numbers from 0 to 9. The description of each cube will be given in three lines showing the six colors of the "open" cube faces, in the format showed in the example below. In the example below, the cube faces has colors from 1 to 6, the face with color 1 is in the opposite side of the face with color 3, and the face with color 2 is neighbor of the faces 1, 3, 4 and 6, and is in the opposite side of the face with color 5.

1
2 4 5 6
3

The final of the input is indicated by N = 0.

## Output

For each test case your program must print one line containing only one integer, corresponding to the number of different cubes in a given set.

 Sample Input Sample Output 3 0 0 7 2 3 1 0 1 2 3 7 0 3 0 0 2 1 7 2 1 1 1 1 1 1 2 2 2 2 2 2 0 2 2