P1780 Painting the Cubes
Description
Xiaopang recently got into 3D objects, especially cubes. He has many cubes and wants them all to look the same, so he decides to repaint some faces of some cubes so that all the cubes become exactly identical. However, Xiaopang is lazy and wants to know the minimum number of repaint operations needed to make all cubes identical.
Two cubes are considered identical if and only if there exists some orientation such that the colors of the corresponding faces match.
The face indices are labeled as follows:

The two cubes shown below are identical.

The two cubes shown below are different.

An example painting plan is shown below:

Input Format
Each test point contains at most $200$ test cases.
For each test case, the first line contains $n$ ($1 \le n \le 4$), the number of cubes. Then follow $n$ lines, each containing $6$ strings $\mathit{color}_1,\allowbreak\mathit{color}_2,\allowbreak\mathit{color}_3,\allowbreak\mathit{color}_4,\allowbreak\mathit{color}_5,\allowbreak\mathit{color}_6$, representing the colors of the $6$ faces of a cube.
Output Format
For each test case, output one integer on a single line, the minimum number of repaint operations required (painting one face counts as one repaint).
Explanation/Hint
Translated by ChatGPT 5