The cat Motanel’s favourite activity is sorting. She generally has a row of blocks in front of her, of distinct sizes, and she tries to sort these in increasing order of size, by using a sequence of swaps. Since cat’s like pairing things, is even. Unfortunately, the dastardly rat Sobo, tries to trick Motanel, and, each time Motanel swaps the block and the block, Sobo will then swap the blocks on positions and . How can Motanel optimally sort the blocks ?
More formally, you are given a permutation . An operation on indices is defined to swap and , and then to swap and .
Task
Given and , create a minimal sequence of operations that sorts .
Input data
There will be multiple test cases in each input file.
On the first line of the input there will be an integer that represents the number of test cases in this file.
On the first line of each test case there will be an integer that represents the value of .
On the next line of each test case will follow 𝑁 integers, that represent respectively.
Output data
Output the answers to the test cases in order.
If there is no way of sorting the permutation, simply print on a new line.
Otherwise, begin by outputting a line that contains two integers and , which represent the length that you think a minimal sequence of operations has, and the length that your sequence of operations has (for partial points, these can be different). Then continue by outputting further lines, each of which will contain two integers and . Such a line represents an operation on indices . Note you may choose to let if you don’t aim at scoring the reconstruction points, for more details see section Scoring. You’ll get points on the subtask of a test if you ever print a negative , or make an invalid move. An invalid move either has or one of the positions out of the range .
Restrictions
In all tests, , is even and is a permutation: any value between and appears exactly once in .
Subtask | Score | Restrictions |
---|---|---|
1 | 15 | and |
2 | 10 | and and for any |
3 | 25 | and |
4 | 15 | and and for any |
5 | 35 | and |
Scoring
Each subtask will be scored independently. The score you’ll get is the score assigned to the subtask multiplied with the minimum ratio among all tests of that subtask. The ratio of a test is computed as follows:
- If there is any subtest where you haven’t properly decided whether a solution exists or not, then the ratio is
- If you’ve made throughout the whole test more than moves, the ratio is
- If you’ve given a correct optimal reconstruction of moves for all subtests inside the test, the ratio for that test is (regardless of whether your guess of optimal length was correct)
- If you’ve computed the correct optimal number of moves and gave a correct, solution for all subtests inside the test, the ratio for that test is
- If you’ve computed the correct optimal number of moves, the ratio is
- If you’ve given a correct reconstruction of moves for every subtest that was solvable, the ratio is
- If you have at least one wrong reconstruction for a subtest, provided you’ve correctly distinguished between when you can sort the permutation and when you can’t, the ratio for the test is
Assume these criteria are considered in this exact order and the coefficient is given by the first condition that matches the case of the current test.
Example
stdin
4
6
2 6 4 3 1 5
10
4 9 6 3 1 10 8 5 2 7
4
4 1 3 2
10
7 8 9 10 5 6 1 2 3 4
stdout
3 3
2 4
2 3
1 2
5 5
2 8
2 5
1 4
1 3
1 2
-1
2 2
2 8
1 7