You are given a permutation of the integers from to .
In one operation, you may choose an index () such that
and swap with (leaving in place).
Determine whether it is possible to sort in ascending order — that is, obtain — using any number of operations (possibly zero). If it is possible, find the minimum number of operations required.
Input
Each test contains multiple test cases. The first line 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 permutation.
The second line of each test case contains distinct integers () --- the elements of the permutation.
It is guaranteed that the sum of over all test cases does not exceed .
Output
For each test case, output a single integer: the minimum number of operations required to sort the permutation in ascending order, or -1 if it is impossible.
Example
stdin
3
5
3 2 1 4 5
4
2 1 4 3
5
5 4 3 2 1
stdout
1
-1
-1
Note
In the first test case, we can choose since (). Swapping and transforms the permutation into , which is sorted in ascending order using operation.
In the second test case, there is no index () satisfying . Since no operation can be performed and the permutation is not sorted, the answer is \texttt{-1}.
In the third test case, although valid operations exist initially (for instance, choosing yields ), it can be proven that no sequence of operations can transform into . Thus, the answer is -1.