Diceoids

The following picture shows four dice. Or are they all dice? Artifacts (a) and (b) are dice; (c) and (d) are not dice, but they are the same — you can see that by a suitable rotation of (d). Thus, here we have two classes of dice-like artifacts (diceoids), classified by comparison under suitable rotations. You are given a bag of diceoids, and your job is to classify them and report how many classes there are. (Your job is not to determine how many are dice.) To facilitate description of diceoids in a text medium, we label the faces of the cube: then a diceoid is encoded as a sequence of six numbers dA, ..., dF , meaning that face i bears di dots. Example: 536214meansthatfaceAhas5dots,faceBhas3dots,faceChas6dots,etc. Itis entirely possible that different faces have the same number of dots, e.g., 2 2 2 3 3 3, but every face has at least 1 dot and at most 6 dots. Input The input file contains several test cases. The description of each test case is given below: Each test case begins with the number of diceoids n (n ≤ 1000), followed by the description of n dicecoids. Output For each test case your program should output the number of classes. Follow the format specified in the output for sample input. Sample Input 7 536214 415326 563241 451362 222333 232332 111111 0

2/2 Sample Output 4