Adjacent Pairs

아직 제출이 없습니다시간 제한3초메모리 제한1024 MB

문제

Let's call an array b_1,b_2,,b_mb\_1, b\_2, \dots , b\_m good, if b_ib_i+1b\_i ≠ b\_{i+1} for any ii with 1im11 ≤ i ≤ m - 1.

You are given a good array of nn positive integers a_1,a_2,a_3,,a_na\_1, a\_2 , a\_3 , \dots , a\_n.

You can perform the following operations on this array:

Choose any index ii (1in1 ≤ i ≤ n) and a number xx (1x1091 ≤ x ≤ 10^9). Then, set a_ia\_i to xx. After this operation, the array has to remain good.

You want to perform several operations so that the resulting array will contain exactly two distinct values. Determine the smallest number of operations needed to achieve this goal.

입력

The first line of input contains the integer tt (1t1051 ≤ t ≤ 10^5), the number of test cases. The description of test cases follows.

The first line of each test case contains a single integer nn (2n21052 ≤ n ≤ 2 ⋅ 10^5) - the length of the array.

The second line of each test case contains nn integers a_1,a_2,,a_na\_1 , a\_2 , \dots , a\_n (1a_in1 ≤ a\_i ≤ n) - elements of the array. It's guaranteed that a_ia_i+1a\_i ≠ a\_{i+1} for 1in11 ≤ i ≤ n - 1 (that is, the array is good).

It is guaranteed that the sum of n over all test cases does not exceed 21052 ⋅ 10^5.

출력

For each test case, output a single integer - the smallest number of operations needed to achieve an array in which there are exactly two distinct values.

힌트

In the first test case, one of the optimal sequences of operations is:

(4,5,2,4,5)(2,5,2,4,5)(2,5,2,4,2)(2,5,2,5,2)(4, 5, 2, 4, 5) → (2, 5, 2, 4, 5) → (2, 5, 2, 4, 2) → (2, 5, 2, 5, 2).

In the second test case, the array already contains only two distinct values, so the answer is 00.