Problem: You are given a permutation of integers to .
You can change the current permutation by applying the following operation several (possibly, zero) times:
- choose some ();
- create a new permutation by: first, writing down all elements of that are less than , without changing their order; second, writing down all elements of that are greater than or equal to , without changing their order;
- replace with the newly created permutation.
For example, if the permutation used to be and you choose , then you will first write down , then append this with . So the initial permutation will be replaced by .
Find the minimum number of operations you need to achieve for . We can show that it is always possible to do so.
A permutation of length is an array consisting of distinct integers from to in arbitrary order. For example, is a permutation, but is not a permutation ( appears twice in the array), and is also not a permutation ( but there is in the array).
Input Format: Each test contains multiple test cases. The first line contains the number of test cases (). The description of the test cases follows.
The first line of each test case contains one integer ().
The second line of each test case contains integers (). It is guaranteed that is a permutation.
It is guaranteed that the sum of over all test cases does not exceed .
Output Format: For each test case, output the answer on a separate line.
Note: In the first test case, and , so there is nothing left to do.
In the second test case, we can choose and we immediately obtain , .
In the third test case, we can achieve the minimum number of operations in the following way:
- : ;
- : ;
- : ;
- : .