#P7690. [CEOI 2002] A decorative fence

[CEOI 2002] A decorative fence

Description

Richard has just finished building his new house. Now the only thing missing is a nice little wooden fence. He does not know how to make a wooden fence, so he decided to order one. Somehow, he got the ACME Fence Catalog 2002\texttt{ACME Fence Catalog 2002}——the flagship resource for nice little wooden fences (note: ACME is a company that makes everything). After reading its preface, he already knows what makes a little wooden fence nice.
A wooden fence consists of NN planks, placed vertically in a row. In addition, the fence looks nice if and only if the following conditions are satisfied:

  • The planks have different lengths, i.e., the lengths are 1,2,,N1,2,\cdots,N.
  • For each plank that has two neighboring planks, it is either larger than both of its neighbors, or smaller than both of its neighbors. (That is, the top of the fence alternates up and down.)

Therefore, each nice fence using NN planks can be uniquely described by a permutation a1,,aNa_1,\cdots,a_N such that (i\forall i1<i<N1 < i < N) (aiai1)×(aiai+1)>0(a_i - a_{i−1}) × (a_i - a_{i+1}) > 0. Conversely, every such permutation describes a nice fence.
Obviously, there can be many different nice wooden fences made of NN planks. The ACME sales manager decided to sort the nice fences and put them into the catalog in the following way: fence A (represented by the permutation a1,,aNa_1,\cdots,a_N) comes before fence B (represented by b1,,bNb_1,\cdots,b_N) if and only if there exists an ii such that (j<i\forall j < i) aj=bja_j = b_j and (ai<bia_i < b_i). (That is, comparing which fence appears earlier in the catalog is equivalent to taking their permutations, finding the first position where they differ, and comparing the values at that position.) All nice fences with NN planks are numbered in the order they appear in the catalog (starting from 11). This number is called their catalog number.
TuLi After carefully inspecting all the nice little wooden fences, Richard decided to order some of them. He wrote down the number of planks NN and the catalog number CC. Later, he met his friends and wanted to show them his fence, but he lost the catalog. The only thing he still has is his notes. Please help him determine what his fence will look like.

Input Format

The first line contains an integer KK. The next KK lines each describe one dataset. Each line contains two integers NN and CC separated by a space, where NN is the number of planks in the fence, and CC is the catalog number of the fence.

Output Format

For each dataset, output one line describing the CC-th fence with NN planks in the list. More precisely, if the fence is the permutation a1,,aNa_1,\cdots,a_N, then the corresponding output line should contain the numbers aia_i (in the correct order), separated by single spaces.

2
2 1
3 3
1 2
2 3 1

Hint

Constraints

For 100%100\% of the testdata, 1K1001 \leq K \leq 100, 1N201 \leq N \leq 20. You may assume that the total number of nice little wooden fences with 2020 planks fits into a 6464-bit signed integer variable (long long in C/C++, int64 in FreePascal). You may also assume that the input is correct; in particular, CC is at least 11 and it does not exceed the number of nice fences with NN planks.

Problem Notes

From CENTRAL-EUROPEAN OLYMPIAD IN INFORMATICS 2002: A decorative fence.
Translated and整理ed by @求学的企鹅.

Translated by ChatGPT 5