#P1792C. Min Max Sort
Min Max Sort
Description
You are given a permutation of length (a permutation of length is an array of length in which each integer from to occurs exactly once).
You can perform the following operation any number of times (possibly zero):
- choose two different elements and and erase them from the permutation;
- insert the minimum of and into the permutation in such a way that it becomes the first element;
- insert the maximum of and into the permutation in such a way that it becomes the last element.
For example, if and we want to apply the operation to the elements and , then after the first step of the operation, the permutation becomes ; and after we insert the elements, it becomes .
Your task is to calculate the minimum number of operations described above to sort the permutation in ascending order (i. e. transform so that ).
The first line contains a single integer () — the number of test cases.
The first line of the test case contains a single integer () — the number of elements in the permutation.
The second line of the test case contains distinct integers from to — the given permutation .
The sum of over all test cases doesn't exceed .
For each test case, output a single integer — the minimum number of operations described above to sort the array in ascending order.
Input
The first line contains a single integer () — the number of test cases.
The first line of the test case contains a single integer () — the number of elements in the permutation.
The second line of the test case contains distinct integers from to — the given permutation .
The sum of over all test cases doesn't exceed .
Output
For each test case, output a single integer — the minimum number of operations described above to sort the array in ascending order.
Note
In the first example, you can proceed as follows:
- in the permutation , let's choose the elements and , then, after applying the operation, the permutation becomes ;
- in the permutation , let's choose the elements and , then, after applying operation, the permutation becomes .