One way that scientists try to measure how one species evolved into another is to find out how the ancestor's genome changed into the other's. Closely related species have several genes in common and it turns out that a good way to compare them is comparing how the common genes changed place.
One of the most common mutations that change the order of a genomes' genes is the reversal. If we model a genome as a sequence of N genes with each gene being an integer from 1 to N, then a reversal is a mutation that changes the genome by reverting the order of a block of consecutive genes. A reversal can be described by two indexes (i, j), 1 <= i <= j <= N, indicating that it reverts the order of the genes within indexes from i to j. So, when it is applied to a genome [g1, ..., gi-1, gi, gi+1, ..., gj-1, gj , gj+1, ..., gN], we obtain the genome [g1, ..., gi-1, gj, gj-1, ..., gi+1, gi, gj+1, ..., gN]. As an example, the reversal (3, 6) applied to the genome [1, 2, 3, 4, 5, 6, 7] gives [1, 2, 6, 5, 4, 3, 7]. If after that the reversal (1, 3) is applied, we obtain the genome [6, 2, 1, 5, 4, 3, 7].
A scientist studying the evolution of a species wants to try a series of reversals on its genome. Then he wants to query the final position of several genes. Would you take the challenge and help him?