Hide

Problem A
Heap Partition

A sequence $S=\{ s_1,s_2,\dots ,s_ n\} $ is called heapable if there exists a binary tree $T$ with $n$ nodes such that every node is labelled with exactly one element from the sequence $S$, and for every non-root node $s_ i$ and its parent $s_ j$, $s_ j \le s_ i$ and $j < i$ hold. Each element in sequence $S$ can be used to label a node in tree $T$ only once.

Chiaki has a sequence $a_1,a_2,\dots ,a_ n$, she would like to decompose it into a minimum number of heapable subsequences.

Note that a subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements.

Input

There are multiple test cases. The first line of input contains an integer $T$, indicating the number of test cases. For each test case:

The first line contain an integer $n$ ($1 \le n \le 10^5$) – the length of the sequence.

The second line contains $n$ integers $a_1, a_2, \dots , a_ n$ ($1 \le a_ i \le n$).

It is guaranteed that the sum of all $n$ does not exceed $2 \times 10^6$.

Output

For each test case, output an integer $m$ denoting the minimum number of heapable subsequences in the first line. For the next $m$ lines, first output an integer $C_ i$, indicating the length of the subsequence. Then output $C_ i$ integers $P_{i1}, P_{i2}, \dots , P_{iC{_ i}}$ in increasing order on the same line, where $P_{ij}$ means the index of the $j$-th element of the $i$-th subsequence in the original sequence.

Sample Input 1 Sample Output 1
4
4
1 2 3 4
4
2 4 3 1
4
1 1 1 1
5
3 2 1 4 1
1
4 1 2 3 4
2
3 1 2 3
1 4
1
4 1 2 3 4
3
2 1 4
1 2
2 3 5

Please log in to submit a solution to this problem

Log in