There are several cubes, all of the same size. Every face of each cube is painted with a single color; two different faces of the same cube may or may not share a color.
Two cubes are identically colored if one of them can be rotated in space so that it looks exactly like the other, face for face. Only rigid rotations of the solid cube are allowed — you may never reflect a cube — so a cube and its mirror image are not necessarily identically colored. A set of cubes is identically colored when every pair of cubes in the set is identically colored.
You may repaint any face of any cube to any color you like. Given a set of cubes, determine the minimum total number of faces that must be repainted so that the whole set becomes identically colored.
The input is a sequence of datasets. Each dataset starts with a line containing one integer $n$ ($1 \le n \le 4$), the number of cubes, followed by $n$ lines, one per cube.
Each cube line lists the colors of its six faces, in the fixed face order $1, 2, 3, 4, 5, 6$, separated by single spaces. The faces are arranged so that faces $1$ and $6$ are opposite, faces $2$ and $5$ are opposite, and faces $3$ and $4$ are opposite; every cube uses this same numbering.
A color name is one or more words joined by hyphens (-), where each word is a nonempty string of lowercase English letters. Each color name is at most $24$ characters long, including any hyphens.
The end of the input is a line that contains a single $0$; it is not a dataset.
For each dataset, print one line with the minimum number of faces that must be repainted to make that set of cubes identically colored.