beecrowd | 1368
# Colorful Cubes

**Timelimit: 1**

By Ricardo Anido Brazil

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.

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.

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 |
2 |