CF2078B.Vicious Labyrinth

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

Vicious Labyrinth

Axium Crisis - ak+q

There are nn cells in a labyrinth, and cell ii (1in1 \leq i \leq n) is nin - i kilometers away from the exit. In particular, cell nn is the exit. Note also that each cell is connected to the exit but is not accessible from any other cell in any way.

In each cell, there is initially exactly one person stuck in it. You want to help everyone get as close to the exit as possible by installing a teleporter in each cell ii (1in1 \leq i \leq n), which translocates the person in that cell to another cell aia_i.

The labyrinth owner caught you in the act. Amused, she let you continue, but under some conditions:

  • Everyone must use the teleporter exactly kk times.
  • No teleporter in any cell can lead to the same cell it is in. Formally, iaii \neq a_i for all 1in1 \leq i \leq n.

You must find a teleporter configuration that minimizes the sum of distances of all individuals from the exit after using the teleporter exactly kk times while still satisfying the restrictions of the labyrinth owner.

If there are many possible configurations, you can output any of them.

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 and only line of each test case contains two integers nn and kk (2n21052 \leq n \leq 2 \cdot 10^5, 1k1091 \leq k \leq 10^9) — the number of cells in the labyrinth and the value kk.

It is guaranteed that the total sum of nn across all test cases does not exceed 21052 \cdot 10^5.

Output

For each test case, output nn integers — the destinations of the teleporters a1,a2,,ana_1, a_2, \ldots, a_n in order, satisfying the given conditions (1ain1 \leq a_i \leq n, aiia_i \neq i).

Note

In the first test case, the position of each person is as follows.

  • Before teleporting: [1,2][1, 2].
  • First teleportation: [2,1][2, 1].

The distance sum is (22)+(21)=1(2-2) + (2-1) = 1, which is the minimum possible.

In the second test case, the position of each person is as follows.

  • Before teleporting: [1,2,3][1, 2, 3].
  • First teleportation: [2,3,2][2, 3, 2].
  • Second teleportation: [3,2,3][3, 2, 3].

The distance sum is (33)+(32)+(33)=1(3-3) + (3-2) + (3-3) = 1, which is the minimum possible.

Samples

2
2 1
3 2
2 1
2 3 2

在线编程 IDE

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