#P1856A. Tales of a Sort
Tales of a Sort
Description
Alphen has an array of positive integers of length .
Alphen can perform the following operation:
- For all from to , replace with .
Alphen will perform the above operation until is sorted, that is satisfies . How many operations will Alphen perform? Under the constraints of the problem, it can be proven that Alphen will perform a finite number of operations.
Each test contains multiple test cases. The first line of input contains a single integer () — the number of test cases. The description of the test cases follows.
The first line of each test case contains a single integer () — the length of the array .
The second line of each test case contains integers () — the elements of the array .
For each test case, output a single integer — the number of operations that Alphen will perform.
Input
Each test contains multiple test cases. The first line of input contains a single integer () — the number of test cases. The description of the test cases follows.
The first line of each test case contains a single integer () — the length of the array .
The second line of each test case contains integers () — the elements of the array .
Output
For each test case, output a single integer — the number of operations that Alphen will perform.
Note
In the first test case, we have . Since is already sorted, Alphen will not need to perform any operations. So, the answer is .
In the second test case, we have . Since is not initially sorted, Alphen will perform one operation to make . After performing one operation, is still not sorted, so Alphen will perform another operation to make . Since is sorted, Alphen will not perform any other operations. Since Alphen has performed two operations in total, the answer is .