CF2046B.Move Back at a Cost

传统题 时间 2000 ms 内存 256 MiB 8 尝试 3 已通过 1 标签

Move Back at a Cost

You are given an array of integers aa of length nn. You can perform the following operation zero or more times:

  • In one operation choose an index ii (1in1 \le i \le n), assign ai:=ai+1a_i := a_i + 1, and then move aia_i to the back of the array (to the rightmost position). For example, if a=[3,5,1,9]a = [3, 5, 1, 9], and you choose i=2i = 2, the array becomes [3,1,9,6][3, 1, 9, 6].

Find the lexicographically smallest^{\text{∗}} array you can get by performing these operations.

^{\text{∗}}An array cc is lexicographically smaller than an array dd if and only if one of the following holds:

  • cc is a prefix of dd, but cdc \ne d; or
  • in the first position where cc and dd differ, the array cc has a smaller element than the corresponding element in dd.

Input

Each test contains multiple test cases. The first line contains the number of test cases tt (1t1041 \le t \le 10^4). The description of the test cases follows.

The first line contains a single integer nn (1n1051 \le n \le 10^5), the length of the array.

The second line contains nn integers a1,a2,,ana_1, a_2, \ldots, a_n (1ai1091 \le a_i \le 10^9), the elements of the array.

It is guaranteed that the sum of nn over all test cases does not exceed 10510^5.

Output

For each test case, print the lexicographically smallest array you can get.

Samples

3
3
2 1 3
5
1 2 2 1 4
6
1 2 3 6 5 4
1 3 3 
1 1 3 3 5 
1 2 3 4 6 7 

在线编程 IDE

建议全屏模式获得最佳体验