#K34202. Reverse Zigzag Books Arrangement

    ID: 25257 Type: Default 1000ms 256MiB

Reverse Zigzag Books Arrangement

Reverse Zigzag Books Arrangement

You are given N books numbered from 1 to N arranged in order, and a positive integer K representing the group size. Your task is to rearrange the books in a "Reverse Zigzag" order. The process is as follows: Divide the sequence of books into consecutive groups of size K (if the last group contains less than K books, process it as is), then reverse each group individually, and finally concatenate the groups to form the final sequence.

For instance, consider the case when N = 6 and K = 2: The original order is [1, 2, 3, 4, 5, 6]. Dividing into groups yields [1,2], [3,4], [5,6]. Reversing each group gives [2,1], [4,3], [6,5], so the final arranged sequence is [2, 1, 4, 3, 6, 5].

The mathematical operation for reversing a group of numbers from i+1 to min(i+K, N) can be represented in \( \LaTeX \) as:

[ \text{Group}_j = {a_l ; | ; a_l = i+j, ; 1 \leq j \leq \min(K, N-i)} ]

inputFormat

The first line of input contains a single integer T representing the number of test cases. Each test case is on a separate line and contains two space-separated integers N and K, where N denotes the total number of books and K denotes the group size for reversal.

outputFormat

For each test case, output a single line containing the rearranged sequence of books. Each number in the sequence should be separated by a single space.

## sample
2
6 2
5 3
2 1 4 3 6 5

3 2 1 5 4

</p>