# 描述

Chiaki has just learned hash in today’s lesson. A hash function is any function that can be used to map data of arbitrary size to data of fixed size. As a beginner, Chiaki simply chooses a hash table of size $n$ with hash function $h(x) = x \mod n$.
Unfortunately, the hash function may map two distinct values to the same hash value. For example, when $n = 9$ we have $h(7) = h(16) = 7$. It will cause a failure in the procession of insertion. In this case, Chiaki will check whether the next position is available or not. This task will not be finished until an available position is found. If we insert $\lbrace 7, 8, 16 \rbrace$ into a hash table of size $9$, we will finally get $\lbrace 16, -1, -1, -1, -1, -1, -1, 7, 8 \rbrace$. Available positions are marked as $-1$.
After done all the exercises, Chiaki became curious to the inverse problem. Can we rebuild the insertion sequence from a hash table? If there are multiple available insertion sequences, Chiaki would like to find the smallest one under lexicographical order.
Sequence $a_1, a_2, …, a_n$ is lexicographically smaller than sequence $b_1, b_2, …, b_n$ if and only if there exists $i$ ($1 ≤ i ≤ n$) satisfy that $a_i < b_i$ and $a_j = b_j$ for all $1 ≤ j < i$.

## 输入描述

There are multiple test cases. The first line of input contains an integer $T$, indicating the number of test cases. For each test case:
The first line of each case contains a positive integer $n$ ($1 ≤ n ≤ 2 \times 10^5$) – the length of the hash table.
The second line contains exactly $n$ integers $a_1,a_2,…,a_n$ ($-1 ≤ a_i ≤ 10^9$).
It is guaranteed that the sum of all $n$ does not exceed $2 \times 10^6$.

## 输出描述

For each case, please output smallest available insertion sequence in a single line. Print an empty line when the available insertion sequence is empty. If there’s no such available insertion sequence, just output $-1$ in a single line.

# 思路

• 当$x$插入到$j$而应该插入到$i = x \pmod n$时，如果$[i, j)$中间有$-1$，则序列不合法。
• 然后我们可以从Hash表中得出的信息就是一个区间里的数要比一个数插入得早。
• 使用数据结构（线段树）优化建图后拓扑排序即可。
• 注意特判空序列的时候要输出一个空行。否则会格式错误（明明就是WA了）

0%