CF2195C.Dice Roll Sequence

传统题 时间 2000 ms 内存 256 MiB 5 尝试 1 已通过 1 标签

Dice Roll Sequence

Consider the following cube DD where numbers xx and 7x7-x lie on opposite sides:

Image generated by Nano Banana Pro.

A sequence bb of integers from 11 to 66 is called a dice roll sequence if it satisfies the following condition:

  • All pairs of adjacent elements lie on adjacent^{\text{∗}} sides of the cube.

For example, [1,4,2][1,4,2] is a dice roll sequence, while [3,4,6,3][3,4,6,3] is not because 33 and 44 are not on adjacent sides of the dice. Additionally, [2,2,4][2,2,4] is not a dice roll sequence because 22 and 22 are on the same (not adjacent) side of the dice.

Given a sequence aa of nn integers from 11 to 66, you can perform the following operation any number of times (possibly zero).

  • Select an index 1in1 \le i \le n and an integer 1x61 \le x \le 6. Then, change the value of aia_i to xx.

Please determine the minimum number of operations required to make aa a dice roll sequence.

^{\text{∗}}Two sides of the cube SS and TT are called adjacent if they share exactly one edge of the cube. Do note that this condition implies STS \neq T as well.

Input

Each test contains multiple test cases. The first line contains the number of test cases tt (1t1041 \le t \le 10^4). The description of the test cases follows.

The first line of each test case contains a single integer nn (1n31051 \le n \le 3 \cdot 10^5).

The second line of each test case contains nn integers a1,a2,,ana_1,a_2,\ldots,a_n (1ai61 \le a_i \le 6).

It is guaranteed that the sum of nn over all test cases does not exceed 31053 \cdot 10^5.

Output

For each test case, output the minimum number of operations required to make aa a dice roll sequence.

Note

For the first test case, the sequence aa is [1,4,2][1,4,2]. As this is already a dice roll sequence, the answer is 00.

For the second test case, the sequence aa is [3,4,6,3][3,4,6,3].

Changing exactly one element, you can get [3,5,6,3][3,\color{red}{5},6,3], which is a dice roll sequence.

For the third test case, the sequence aa is [6,1,4,3,1,3,2,5,4,4][6,1,4,3,1,3,2,5,4,4].

Changing exactly 44 elements, you can get $[\color{red}{5},1,4,\color{red}{2},1,3,2,\color{red}{1},\color{red}{5},4]$, which is a dice roll sequence.

Samples

3
3
1 4 2
4
3 4 6 3
10
6 1 4 3 1 3 2 5 4 4
0
1
4

在线编程 IDE

建议全屏模式获得最佳体验