Magic Cube Battle
题号:NC212626
时间限制:C/C++/Rust/Pascal 3秒,其他语言6秒
空间限制:C/C++/Rust/Pascal 64 M,其他语言128 M
64bit IO Format: %lld

题目描述

Super Brain is a famous scientific reality and talent show aiming to find people with exceptional brainpower.

In one of the challenges called *Magic Cube Battle*, at first, various kinds of Magic Cubes are given to the contestant. Here shows the picture:



Among these Magic Cubes, one of them is a 2 × 2 × 2 cube, which means 8 mini-cubes construct it. For a combination of 2 × 2 mini-cubes which sharing a whole cube face, you can twist it 90 degrees in a clockwise or counterclockwise direction, and this twist operation is called one twist step.

More specifically, considering all faces of mini-cubes, there will be 24 faces painted in at most 6 different colours in total, and there will be precisely 4 faces painted in each kind of colour. If 4 mini-cubes' faces of the same colour rely on the same large cube face, we can call the large cube face as a completed face. Here shows the picture:



Because of the time for the contestant to twist the Magic Cube is very limited, for each state of the cube, the contestant is eager to know the possible number of completed faces after some foreseeable operation steps at most and at least.

Now you are asked to write a program to help them tackle this problem. Given a colour arrangement of all 24 faces from a scrambled 2 × 2 × 2 cube, please calculate the maximum and the minimum possible number of completed faces in no more than N twist steps.

Index of each face is shown as below:


输入描述:

There are multiple test cases. The first line of the input contains an integer T (1 ≤ T ≤ 35), indicating the number of test cases.

Each test case contains two lines. One integer N (0 ≤ N ≤ 7) in the first line, then 24 integers C_i (0 ≤ C_i) seperated by a single space in the second line. For index 0 ≤ i < 24, C_i is color of the corresponding face.

It's guarantee that the color arrangement is a valid state which can be achieved by doing a finite number of twist steps from an initial cube whose all 6 large cube faces are completed faces.

输出描述:

For each test case, please output the maximum number and the minimum number of completed faces during no more than N twist step(s), respectively. 
示例1

输入

复制
2
1
0 0 0 0 1 1 2 2 3 3 1 1 2 2 3 3 4 4 4 4 5 5 5 5
1
0 4 0 4 1 1 2 5 3 3 1 1 2 5 3 3 4 0 4 0 5 2 5 2

输出

复制
6 2
2 0