eolymp
bolt
Try our new interface for solving problems

Crane

There are n crates waiting to be loaded onto a ship. The crates are numbered \textbf{1}, \textbf{2}, ..., \textbf{n}, the numbers determining the order of loading. Unfortunately, someone messed up the transit and the crates are standing in a row in an arbitrary order. As there is only limited space in the dock area, you must sort the crates by swapping some of them. You are given a crane that works in the following way: you select a connected interval of crates of even length. The crane then exchanges the first half of the interval with the second half. The order inside both halves remains unchanged. Determine the sequence of crane moves that reorders the crates properly. The crane’s software has a bug: the move counter is a \textbf{9}-based (not \textbf{10}-based, as you might think) integer with at most \textbf{6} digits. Therefore, the crane stops working (and has to be serviced) after \textbf{9^6 = 531441} moves. Your solution must fit within this limit. \InputFile The first line of input contains the number of test cases \textbf{T}. The descriptions of the test cases follow: Each test case starts with an integer \textbf{n}, \textbf{1} ≤ \textbf{n} ≤ \textbf{10000}, denoting the number of crates. In the next line a permutation of numbers \{\textbf{1}, \textbf{2}, ..., \textbf{n}\} follows. \OutputFile For each test case print a single line containing \textbf{m} -- the number of swaps -- followed by \textbf{m} lines describing the swaps in the order in which they should be performed. A single swap is described by two numbers -- the indices of the first and the last element in the interval to be exchanged. Do not follow the crane’s strange software design -- use standard decimal numeral system.
Time limit 5 seconds
Memory limit 256 MiB
Input example #1
2
6
5 4 6 3 2 1
5
1 2 3 4 5
Output example #1
5
1 2
4 5
5 6
4 5
1 6
0
Source ACM ICPC Central Europe Regional Contest 2013, Kraków, November 15-17, 2013