P18141 [NWRRC 2026] Just Stack It

Description

Jane found $n$ disks from a stacking toy in the attic. She wants to arrange them on rods, each of which can hold at most $k$ disks. On each rod, the disk sizes must increase strictly from top to bottom. The numbers on the disks in the figures below indicate their sizes. ![](https://cdn.luogu.com.cn/upload/image_hosting/wrtx0x2z.webp) Valid stacks for $k = 3$. Sample output for the first test case. ![](https://cdn.luogu.com.cn/upload/image_hosting/8v0w1ces.webp) Invalid stacks for $k = 3$. Jane may rearrange the disks in any order and use as many rods as needed. Help her correctly stack all the disks using as few rods as possible.

Input Format

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 20$). The description of the test cases follows. The first line of each test case contains two integers $n$ and $k$, denoting the number of disks and the maximum number of disks on a rod ($1 \le k \le n \le 100$). The second line contains $n$ integers $a_1, a_2, \ldots, a_n$, denoting the sizes of the disks ($1 \le a_i \le n$). It is guaranteed that the sum of $n$ over all test cases does not exceed $100$.

Output Format

For each test case, print an integer $r$, denoting the minimum possible number of rods required to correctly stack all $n$ disks. Then describe the $r$ rods in any order. For rod $i$, print an integer $s_i$, denoting the number of disks on it ($1 \le s_i \le k$), followed by $s_i$ integers denoting their sizes from top to bottom, in strictly increasing order. Each input disk must be used exactly once. If there are multiple answers, print any of them.