Adjacent Pairs

Time limit: 2s Memory limit: 256MB Input: Output:

Let's call an array b1,b2,,bmb_1, b_2, \dots, b_m good, if bibi+1b_i \neq b_{i+1} for any ii with 1im11 \leq i \leq m-1. You are given a good array of nn positive integers a1,a2,a3,,ana_1, a_2, a_3, \dots, a_n.

You can perform the following operations on this array:

  • Choose any index ii (1in1 \leq i \leq n) and a number xx. Then, set aia_i to xx. After this operation, the array has to remain good.

Task

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.

Input data

The first line of input contains the integer tt, the number of test cases. The description of test cases follows.

The first line of each test case contains a single integer nn — the length of the array.

The second line of each test case contains nn integers a1,a2,,ana_1, a_2 ,\dots, a_n — elements of the array. It's guaranteed that aiai+1a_i \neq a_{i+1} for 1in11 \leq i ≤ n − 1 (that is, the array is good).

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

Output data

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.

Constraints and clarifications

  • 1t1051 \leq t \leq 10^5
  • 2n21052 \leq n \leq 2 \cdot 10^5
  • 1an1 \leq a \leq n
  • 1x1091 \leq x \leq 10^9
  • For 2020 points, the sum of nn over all test cases does not exceed 100100.
  • For another 1010 points, the sum of nn over all test cases does not exceed 500500.
  • For another 2525 points, the sum of nn over all test cases does not exceed 4 0004\ 000.

Example

stdin

2
5
4 5 2 4 5
2
1 2

stdout

3
0

Note

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) \rightarrow (2,5,2,4,5) \rightarrow (2,5,2,4,2) \rightarrow (2,5,2,5,2).

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

Log in or sign up to be able to send submissions!