#P5919. [POI 2004] MAK
[POI 2004] MAK
Problem Description
A permutation is a one-to-one function mapping of elements . The order of a permutation is the smallest such that for all , the following holds:
( times in total).
For example, for elements, the permutation with order is , because .
For a given , we want a permutation of length whose order is as large as possible. For example, among permutations of length , the maximum possible order is .
One example is .
Among all permutations that achieve the maximum order, we need to find the lexicographically smallest one.
More precisely, we say permutation is smaller than permutation if there exists an such that for all we have and . Then, among permutations of length , the smallest one is .
Input Format
The first line contains an integer , meaning there are test cases.
The next lines give the lengths .
Output Format
Output lines, each containing one optimal permutation.
2
5
14
2 1 4 5 3
2 3 1 5 6 7 4 9 10 11 12 13 14 8
Hint
For of the testdata, and .
Translated by ChatGPT 5