Missing Blueprint

View as PDF

Submit solution


Points: 1
Time limit: 3.0s
Memory limit: 256M

Problem types

Professor EHENG is a well known architect, known for his works in modern architecture as well as art. For his latest work, he decided to create a one of a kind staircase for the computer engineering building. On his way to grab a coffee during a visit to the building, he suddenly realizes that he lost his blueprint for this unique staircase. He can only remember the dimensions of the staircase, and has access to an e-mail written by one of his students discussing a special property of the blueprint. Can you help Professor EHENG remember this masterpiece?

The staircase can be described as an array \(\mathbf{B}\) with integer elements representing the height of the steps.

\(\mathbf{B}\) has length \(\mathbf{N}\) and height \(\mathbf{H}\) as its dimensions. It is known to have elements between \(\mathbf{1}\) and \(\mathbf{H}\) inclusively. Therefore, the height dimension \(\mathbf{H}\) both describes the height and the maximum element of \(\mathbf{B}\).

The special property \(\mathbf{SP}\) is given as an array consisting of \(\mathbf{N}\) numbers, and can be built from the blueprint \(\mathbf{B}\) by following the pattern below:

\(\mathbf{SP_i} = \sum_{j=0}^{i-1}(1 \text{ if } \mathbf{B_j} \leq \mathbf{B_i} \text{ else } 0)\)

Informally, it can be said that each index \(i\) of \(\mathbf{SP}\) counts the number of elements in the subarray \(\mathbf{B_0}, \mathbf{B_1}, .. ,\mathbf{B_{i-1}}\) smaller than or equal to \(\mathbf{B_i}\).

It is guaranteed that with the given dimensions, the staircase will be unique. Thus, \(\mathbf{B}\) cannot be constructed if all \(\mathbf{B_i} < \mathbf{H}\).

Input

The first line contains a single number \(\mathbf{T}\), the number of test cases.

Then for each test case, the following input is given:

For the first line of the current test case, the dimensions of the special property array \(\mathbf{SP}\) is given as two numbers \(\mathbf{N}\) and \(\mathbf{H}\), \(\mathbf{N}\) denoting the length of both the array \(\mathbf{SP}\) and \(\mathbf{B}\); and \(\mathbf{H}\) denoting the height of the array \(\mathbf{B}\).

The next line of the current test case consists of \(\mathbf{N}\) integers, the elements of \(\mathbf{SP}\).

  • \(1 \leq \mathbf{H} \leq \mathbf{SP_i} \leq \mathbf{N} \leq 10^5\)
  • \(1 \leq \mathbf{B_i} \leq \mathbf{H}\)

It is guaranteed that the total number of elements in all the test cases won't exceed \(10^5\).

Output

For each test case, print the elements of the staircase array \(\mathbf{B}\) that is unique to the conditions of the test case's \(\mathbf{H}\) and \(\mathbf{SP}\) values.

Examples

Input 1:

1
6 2
0 1 2 1 2 3

Output 1:

1 2 2 1 1 1

Input 2:

2
5 3
0 1 1 3 1
6 3
0 0 1 0 3 4

Output 2:

1 3 2 3 1
3 2 2 1 2 2

Explanation

Input 1: The special property array \(\mathbf{SP}\) can be constructed from the staircase array \(\mathbf{B}\) like so:

\(\mathbf{SP_0}=0\) from \(\mathbf{B}=[\underline{1},-,-,-,-,-]\)

\(\mathbf{SP_1}=1\) from \(\mathbf{B}=[\mathbf{1},\underline{2},-,-,-,-]\)

\(\mathbf{SP_2}=2\) from \(\mathbf{B}=[\mathbf{1},\mathbf{2},\underline{2},-,-,-]\)

\(\mathbf{SP_3}=1\) from \(\mathbf{B}=[\mathbf{1},2,2,\underline{1},-,-]\)

\(\mathbf{SP_4}=2\) from \(\mathbf{B}=[\mathbf{1},2,2,\mathbf{1},\underline{1},-]\)

\(\mathbf{SP_5}=3\) from \(\mathbf{B}=[\mathbf{1},2,2,\mathbf{1},\mathbf{1},\underline{1}]\)

Above, the underline signifies the current index being processed, whereas the bold is used to describe the elements that are smaller than or equal to the element being processed.