#P11446. 「ALFR Round 3」B Swap & Delete

「ALFR Round 3」B Swap & Delete

Description

Given a sequence of length nn, denoted as a1,a2,a3,,ana_1, a_2, a_3, \dots, a_n, you need to perform kk operations to make this sequence empty.

Each operation can be one of the following:

  1. Select two indices i,ji, j and swap aia_i and aja_j, satisfying 1i<jn1 \le i < j \le n.
  2. Select two indices i,ji, j and delete the elements ai,ai+1,,aja_i, a_{i+1}, \dots, a_j, satisfying 1ijn1 \le i \le j \le n, and ai=aja_i = a_j.

You should output the minimum number of operations kk required.

Input Format

The first line contains a positive integer TT (1T51 \le T \le 5), indicating the number of test cases.

For each test case:

The first line contains a positive integer nn (1n1051 \le n \le 10^5), representing the length of the sequence.

The second line contains nn positive integers a1,a2,,ana_1, a_2, \ldots, a_n (0ai1090 \le a_i \le 10^9).

Output Format

For each test case, output a single integer kk, indicating the minimum number of operations.

2
5
1 2 3 2 3
3
1000000000 1000000000 99999999
2
2

Hint

Subtask Score Constraints
11 1010 n3n \le 3
22 2020 n10n \le 10
33 ai2a_i \le 2
44 1010 All aia_i are guaranteed to be equal
55 4040 -

For all the tests, 1T51 \le T \le 5, 1n1051 \le n \le 10^5, 0ai1090 \le a_i \le 10^9.