Random unrelated information: In chess, it is illegal to move 2 pawns simultaneously in the first move. If you are doing this, please do me a favor and stop.
You have an n × 8 chess board. Rows are numbered 1 to 8 from bottom to top. Columns are numbered 1 to n from left to right. Initially there are n rooks on the bottom row. You also have a permutation p1, p2, ..., pn. A permutation is a sequence of n integers from 1 to n, in which all the numbers occur exactly once.
You have to move the rooks such that the rook which was initially at column i, ends up at column pi of the bottom row. You also have to minimize the number of moves.
In a move a rook can move horizontally or vertically, but not over another rook. Two rooks can never be on the same cell at the same time.
Input
The first line contains the number of test cases T. First line of each test case has an integer n. The second line has n space separated integers p1, p2, ..., pn.
Constraints
- 1 ≤ T ≤ 100
- 1 ≤ n ≤ 105
- The sum of n over all test cases doesn’t exceed 105
Output
For each case, print the case number and the output the minimum number of moves k. Each of the next k lines contain 4 integers c1, r1, c2, r2 meaning a rook is moved from column c1 row r1 to column c2 row r2. If there are multiple possible outputs, print any. Do not print trailing whitespaces in any line.
Sample
Sample Input | Sample Output |
---|---|
1 5 2 3 5 4 1 | Case 1: 8 3 1 3 2 2 1 3 1 5 1 5 5 3 2 5 2 1 1 2 1 5 5 1 5 1 5 1 1 5 2 5 1 |