logo AlgoBeat OnlineJudge
登录 注册

#209287. [EC Final 2022] Minimum Suffix

内存限制:1024 MiB 时间限制:3000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

For a string of length , we define if is the minimum suffix of , for all . (A suffix is the minimum suffix of a string if it is lexicographically smaller than any other suffix of that string.)

You are to recover from . If there are multiple answers, find the lexicographically smallest one.

输入格式

The first line contains a single integer () representing the number of test cases.

For each test case, the first line contains a single integer () representing the length of . The next line contains integers ( for all ).

It is guaranteed that the sum of over all test cases does not exceed .

输出格式

For each test case, output one line. If there is no solution, output . Otherwise, output the lexicographically smallest . Characters of are represented by positive integers. Smaller integers represent smaller characters in the lexicographical order.

样例

样例输入 1

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

1 2 2
-1
1 2 1
1 1 2
2 1 2
1 1 1

数据范围与提示

As the input/output can be huge, it is recommended to use fast input/output methods.