Home STD Contest Notification Clarification Problems Ranklist Status Print Sign Out
因为最近重新配置了服务器,造成内核的不稳定,非常抱歉。More...

Permutation

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 102400/102400 K (Java/Others)
Total Submission(s): 169    Accepted Submission(s): 42


Problem Description
A permutation of n elements is a one-to-one function (injection) p: {1,2,...,n} -> {1,2,...,n}. An order of permutation p is the minimal k >= 1, such that for all i=1,2,...,n we have:
p(p(....p(i)...)) = i

That is, p composed with itself k times becomes identity function. For example, the order of the permutation of 3 elements p(1)=3, p(2)=2, p(3)=1 is 2, because p(p(1))=1, p(p(2))=2, p(p(3))=3.
For a given n let us consider permutations of n-elements having the the largest order possible. For example, the maximal order of a permutation of 5 elements is 6. An example of a permutation of 5 elements whose order is 6 is p(1)=4, p(2)=5, p(3)=2, p(4)=1, p(5)=3.
Among all permutations of n elements having the maximal order, we would like to find the earliest one (in a lexycographic order). Being more precise, we say a permutation p of n elements is earlier than a permutation r of n elements, if there is i, such that p(j) = r(j) for all j < i and p(i) < r(i). The earliest permutation of 5 elements having an order 6 is p(1)=2,p(2)=1,p(3)=4,p(4)=5,p(5)=3.
 

Input
There is one positive integer t (1 <= t <= 30) in the first line of the standard input. In the following T lines there are positive integers N1, N2, ..., Nt, one per line, 1 <= ni <= 10000.
 

Output
Your programme should write t lines to the standard output. The ith line should contain a sequence of integers separated by spaces, forming the least permutation of ni elements having the maximal order, i.e. the sequence p(1), p(2), ..., p(Ni), where p denotes this permutation.
 

Sample Input
2 5 14
 

Sample Output
2 1 4 5 3 2 3 1 5 6 7 4 9 10 11 12 13 14 8
 

Statistic | Submit | Clarifications | Back