#P1506E. Restoring the Permutation
Restoring the Permutation
No submission language available for this problem.
Description
A permutation is a sequence of integers from to , in which all numbers occur exactly once. For example, , , are permutations, and , , are not.
Polycarp was presented with a permutation of numbers from to . However, when Polycarp came home, he noticed that in his pocket, the permutation had turned into an array according to the following rule:
- .
Now Polycarp wondered what lexicographically minimal and lexicographically maximal permutations could be presented to him.
An array of length is lexicographically smaller than an array of length if there is an index () such that the first elements of arrays and are the same, and the -th element of the array is less than the -th element of the array . For example, the array is lexicographically smaller than the array .
For example, if and , then and the following permutations could have been as initially:
- (lexicographically minimal permutation);
- ;
- ;
- (lexicographically maximum permutation).
For a given array , find the lexicographically minimal and lexicographically maximal permutations that could have been originally presented to Polycarp.
The first line contains one integer (). Then test cases follow.
The first line of each test case contains one integer ().
The second line of each test case contains integers ().
It is guaranteed that the array was obtained by applying the rule from the statement to some permutation .
It is guaranteed that the sum of over all test cases does not exceed .
For each test case, output two lines:
- on the first line output integers — lexicographically minimal permutation that could have been originally presented to Polycarp;
- on the second line print integers — lexicographically maximal permutation that could have been originally presented to Polycarp;
Input
The first line contains one integer (). Then test cases follow.
The first line of each test case contains one integer ().
The second line of each test case contains integers ().
It is guaranteed that the array was obtained by applying the rule from the statement to some permutation .
It is guaranteed that the sum of over all test cases does not exceed .
Output
For each test case, output two lines:
- on the first line output integers — lexicographically minimal permutation that could have been originally presented to Polycarp;
- on the second line print integers — lexicographically maximal permutation that could have been originally presented to Polycarp;