染色的立方体

题目描述

小胖最近迷上了3D物体,尤其是立方体。他手里有很多个立方体,他想让所有的立方体全都长得一样,所以他决定给某些立方体的表面重涂颜色,使得所有的立方体完全相同。但是小胖是很懒的,他想知道最少涂多少次颜色,可以让所有立方体完全相同。

输入输出格式

输入格式


每个测试点包含至多 $200$ 组数据。 每组数据第一行 $n\ (1≤n≤4)$,表示立方体的数量,接下来 $n$ 行,每行 $6$ 个字符串 $\mathit{color}_1,\allowbreak\mathit{color}_2,\allowbreak\mathit{color}_3,\allowbreak\mathit{color}_4,\allowbreak\mathit{color}_5,\allowbreak\mathit{color}_6$,表示立方体 $6$ 个面的颜色。 其中,面的标号如下: ![](https://cdn.luogu.com.cn/upload/image_hosting/xlfu6oe0.png) 两个立方体被视为相同,当且仅当它们可以在某种摆放方式下,每个面的颜色都对应相同。 如下图所示的两个立方体是相同的。 ![](https://cdn.luogu.com.cn/upload/image_hosting/equmi6mp.png) 如下图所示的两个立方体是不同的。 ![](https://cdn.luogu.com.cn/upload/image_hosting/jqp05oyq.png) 一种涂色的方案如下: ![](https://cdn.luogu.com.cn/upload/image_hosting/mewvgalo.png)

输出格式


每组数据,输出一行一个整数,表示最少的涂色数。(涂一个面算一次涂色)

输入输出样例

输入样例 #1

3
scarlet green blue yellow magenta cyan
blue pink green magenta cyan lemon
purple red blue yellow cyan green
2
red green blue yellow magenta cyan
cyan green blue yellow magenta red
2
red green gray gray magenta cyan
cyan green gray gray magenta red
2
red green blue yellow magenta cyan
magenta red blue yellow cyan green
3
red green blue yellow magenta cyan
cyan green hlue yellow magenta red
magenta red blue yellow cyan green
3
blue green green green green blue
green blue blue green green green
green green green green green sea-green
3
red yellow red yellow red yellow
red red yellow yellow red yellow
red red red red red red
4
violet violet salmon salmon salmon salmon
violet salmon salmon salmon salmon violet
violet violet salmon salmon violet violet
violet violet violet violet salmon salmon
1
red green hlue yellow magenta cyan
4
magenta pink red scarlet vermilion wine-red
aquamarine blue cyan indigo sky-blue turciuoise-blue
blond cream chrome-yellow lemon olive yellow
chrome-green emerald-green green olive vilidian sky-blue
0

输出样例 #1

4
2
0
0
2
3
4
4
0
16