problems / 220

The Archivist's Inspection

medium constructive divide-and-conquer sorting math 1000 ms · 256 MB

The Archivist's Inspection

The head archivist has a strict routine for checking a shelf of volumes numbered 1 to n. Every inspection she performs is applied to a contiguous stretch of the shelf, and it goes like this:

  1. She writes one tick in her logbook.
  2. If the volumes in the stretch already stand in increasing order of their numbers from left to right (a stretch of a single volume always does), she walks away.
  3. Otherwise she splits the stretch into a left part made of its first ⌈len/2⌉ volumes and a right part made of the remaining ⌊len/2⌋ volumes, where len is the length of the stretch. She inspects the left part completely, then inspects the right part completely, and finally rearranges the whole stretch into increasing order.

Each morning she starts with one inspection of the entire shelf. Note that a part is checked for order at the moment its own inspection begins, so the right part is checked after the left part has already been inspected and rearranged.

Her apprentice Bob is setting the shelf up for tomorrow and wants her logbook to end up with exactly k ticks. Help Bob: find an arrangement of the volumes 1, 2, …, n on the shelf for which the morning inspection writes exactly k ticks, or report that no arrangement does.

Input

The first line contains t (1 ≤ t ≤ 10^4), the number of test cases. Each of the next t lines contains two integers n and k (1 ≤ n ≤ 2·10^5, 1 ≤ k ≤ 10^9). The sum of n over all test cases does not exceed 2·10^5.

Output

For each test case, print one line. If no arrangement gives exactly k ticks, print -1. Otherwise print n distinct integers from 1 to n: the volume numbers on the shelf from left to right.

If several arrangements work, print any of them.

Notes

In the first example, the shelf 1 3 2 is not in order (tick 1), so it is split into 1 3 and 2. Both parts are in order, giving ticks 2 and 3. For the shelf 3 1 4 2, the whole shelf gets a tick and is split into 3 1 and 4 2; each of those gets a tick, is out of order and splits into two single volumes, which get one tick each. That is 1 + 3 + 3 = 7 ticks. For n = 4, k = 4 no arrangement works.

In the second example, the last shelf is 4 1 2 3 6 5. The whole shelf (tick 1) splits into 4 1 2 and 3 6 5. The part 4 1 2 (tick 2) splits into 4 1 (tick 3, then two more ticks for 4 and 1) and 2 (tick 6). The part 3 6 5 (tick 7) splits into 3 6, which is in order (tick 8), and 5 (tick 9).

Any correct answer is accepted.

Example 1

Input

3
3 3
4 7
4 4

Output

1 3 2
3 1 4 2
-1

Example 2

Input

4
1 1
1 2
5 1
6 9

Output

1
-1
1 2 3 4 5
4 1 2 3 6 5

Hints · reveal one at a time if you're stuck

Hint 1

Draw the inspection tree: each stretch of length at least 2 has two child parts. Each inspected stretch writes one tick, and a stretch that is found out of order causes its two parts to be inspected. What is the most ticks a shelf of n volumes can produce, and which tick counts are possible at all?

Hint 2

Start from the sorted shelf. Making one stretch out of order is easy: swap the two volumes that sit on either side of its split point. Check what this does to each half and to the stretch as a whole.

Hint 3

Each such swap adds exactly two ticks, so choose which stretches to swap by working down from the whole shelf. If a stretch is swapped, its parts must also be inspected, so pick them in a way that keeps the swapped stretches connected to the root, and stop once you have the number of ticks you need.

report an issue Prefer your own editor? sooks prep 220 (CLI)
Sign in to run code

Run your code on the examples, or submit it against every test.