P7690 [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 $\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 $N$ 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,\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 $N$ planks can be uniquely described by a permutation $a_1,\cdots,a_N$ such that ($\forall i$,$1 < i < N$) $(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 $N$ 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 $a_1,\cdots,a_N$) comes before fence B (represented by $b_1,\cdots,b_N$) if and only if there exists an $i$ such that ($\forall j < i$) $a_j = b_j$ and ($a_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 $N$ planks are numbered in the order they appear in the catalog (starting from $1$). This number is called their catalog number. ![TuLi](https://cdn.luogu.com.cn/upload/image_hosting/9kopwi5p.png) After carefully inspecting all the nice little wooden fences, Richard decided to order some of them. He wrote down the number of planks $N$ and the catalog number $C$. 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 $K$. The next $K$ lines each describe one dataset. Each line contains two integers $N$ and $C$ separated by a space, where $N$ is the number of planks in the fence, and $C$ is the catalog number of the fence.

Output Format

For each dataset, output one line describing the $C$-th fence with $N$ planks in the list. More precisely, if the fence is the permutation $a_1,\cdots,a_N$, then the corresponding output line should contain the numbers $a_i$ (in the correct order), separated by single spaces.

Explanation/Hint

#### Constraints For $100\%$ of the testdata, $1 \leq K \leq 100$, $1 \leq N \leq 20$. You may assume that the total number of nice little wooden fences with $20$ planks fits into a $64$-bit signed integer variable (`long long` in C/C++, `int64` in FreePascal). You may also assume that the input is correct; in particular, $C$ is at least $1$ and it does not exceed the number of nice fences with $N$ planks. #### Problem Notes From CENTRAL-EUROPEAN OLYMPIAD IN INFORMATICS 2002: [A decorative fence](https://web.ics.upjs.sk/ceoi/documents/tasks/fence-tsk.pdf). Translated and整理ed by @[求学的企鹅](/user/271784). Translated by ChatGPT 5