#P9395. 橙垒球
橙垒球
Problem Description
Baseball really likes a problem called Mini Something · Suffix, and also greatly admires the author of that problem, so they made a similar problem.
Given a sequence of length , construct a lexicographically maximum string of length such that:
-
Each character of is an integer from to , and the order of characters is as the smallest and as the largest.
-
For the prefix of with length , the length of its lexicographically maximum suffix is exactly .
Output such a , or report that there is no solution.
This problem contains multiple test cases in a single test point.
Input Format
The first line contains an integer , which is the number of test cases.
Then follow test cases. For each test case:
The first line contains an integer .
The second line contains integers .
Output Format
For each test case:
If there is no solution, output one line with a single integer .
If there is a solution, output one line with integers, representing the string you constructed.
6
3
1 1 1
3
1 1 2
3
1 1 3
3
1 2 1
3
1 2 2
3
1 2 3
1 2 3
2 3 3
-1
2 2 3
-1
3 3 3
Hint
Sample Explanation
For the string , for each prefix, the length of its maximum suffix is exactly , and it is the lexicographically maximum string satisfying this condition.
For the string , for each prefix, the length of its maximum suffix is exactly , and it is the lexicographically maximum string satisfying this condition.
There does not exist a string such that for each prefix, the length of its maximum suffix is exactly .
For the string , for each prefix, the length of its maximum suffix is exactly , and it is the lexicographically maximum string satisfying this condition.
There does not exist a string such that for each prefix, the length of its maximum suffix is exactly .
For the string , for each prefix, the length of its maximum suffix is exactly , and it is the lexicographically maximum string satisfying this condition.
Scoring
The score of each test point equals the minimum score among all testdata within it. The score of a single testdata is determined as follows:
If your output format is wrong (i.e., it does not meet the output format requirements), you get no score.
Otherwise, if you correctly determine whether a solution exists (i.e., output for unsolvable testdata, and output numbers in for solvable testdata), you can get of the score.
On this basis, if the test point is unsolvable, or it is solvable and you output a valid solution (not necessarily the lexicographically maximum one), you can get an additional of the score.
On this basis, if the test point is unsolvable, or it is solvable and you output the lexicographically maximum solution, you can get an additional of the score.
Constraints
For all testdata: , , , .
| Subtask ID | Special Property | Score | |
|---|---|---|---|
| Guaranteed no solution | |||
| Guaranteed solvable | |||
| None |
Hint
Please use fast input/output methods.

Translated by ChatGPT 5