Problem: You are given a sequence , consisting of integers.
You can apply the following operation to this sequence: choose some integer and move all elements equal to either to the beginning, or to the end of . Note that you have to move all these elements in one direction in one operation.
For example, if , you can get the following sequences in one operation (for convenience, denote elements equal to as -elements):
- if you move all -elements to the beginning;
- if you move all -elements to the end;
- if you move all -elements to the beginning;
- if you move all -elements to the end;
- if you move all -elements to the beginning;
- if you move all -elements to the end;
You have to determine the minimum number of such operations so that the sequence becomes sorted in non-descending order. Non-descending order means that for all from to , the condition is satisfied.
Note that you have to answer independent queries.
Input Format: The first line contains one integer () — the number of the queries. Each query is represented by two consecutive lines.
The first line of each query contains one integer () — the number of elements.
The second line of each query contains integers () — the elements.
It is guaranteed that the sum of all does not exceed .
Output Format: For each query print one integer — the minimum number of operation for sorting sequence in non-descending order.
Note: In the first query, you can move all -elements to the beginning (after that sequence turn into ) and then move all -elements to the end.
In the second query, the sequence is sorted initially, so the answer is zero.
In the third query, you have to move all -elements to the beginning.