Maximal Orders of Permutations

No attempts yetTime limit3sMemory limit512 MB

Problem

A permutation of nn elements is a bijection π:{1,2,,n}{1,2,,n}\pi:\{1,2,\dots,n\}\to\{1,2,\dots,n\}.

The order of a permutation π\pi is the smallest integer k1k\ge 1 such that applying π\pi to every element kk times returns each element to itself:

π(π(π(i)))k times=ifor all i=1,2,,n,\underbrace{\pi(\pi(\cdots\pi(i)\cdots))}_{k\text{ times}} = i \quad\text{for all } i=1,2,\dots,n,

that is, π\pi composed with itself kk times is the identity. For example, for n=3n=3 the permutation π(1)=3, π(2)=2, π(3)=1\pi(1)=3,\ \pi(2)=2,\ \pi(3)=1 has order 22, because π(π(i))=i\pi(\pi(i))=i for every ii.

For a given nn, consider the permutations of nn elements whose order is as large as possible. For instance, the maximal order over all permutations of 55 elements is 66; one permutation of 55 elements with order 66 is π(1)=4, π(2)=5, π(3)=2, π(4)=1, π(5)=3\pi(1)=4,\ \pi(2)=5,\ \pi(3)=2,\ \pi(4)=1,\ \pi(5)=3.

Among all permutations of nn elements that attain this maximal order, we want the lexicographically smallest one. Formally, a permutation π\pi is earlier than a permutation σ\sigma if there is an index ii with π(j)=σ(j)\pi(j)=\sigma(j) for all j<ij<i and π(i)<σ(i)\pi(i)<\sigma(i). For n=5n=5, the lexicographically smallest permutation of order 66 is π(1)=2, π(2)=1, π(3)=4, π(4)=5, π(5)=3\pi(1)=2,\ \pi(2)=1,\ \pi(3)=4,\ \pi(4)=5,\ \pi(5)=3.

Write a program that reads several values n1,n2,,ndn_1,n_2,\dots,n_d and, for each nin_i, outputs the lexicographically smallest permutation of nin_i elements whose order is maximal.

Input

The first line contains a single integer dd (1d101\le d\le 10). Each of the next dd lines contains one integer nin_i (1ni100001\le n_i\le 10000).

Output

Print dd lines. The ii-th line must contain the sequence π(1),π(2),,π(ni)\pi(1),\pi(2),\dots,\pi(n_i) — the lexicographically smallest permutation of nin_i elements whose order is maximal — with the numbers separated by single spaces.