Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
Register

Language:
The shuffle Problem
 Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 2121 Accepted: 705

Description

Any case of shuffling of n cards can be described with a permutation of 1 to n. Thus there are totally n! cases of shuffling. Now suppose there are 5 cards, and a case of shuffle is <5, 3, 2, 1, 4>, then the shuffle will be:

Before shuffling：1, 2, 3, 4, 5
The 1st shuffle：5, 3, 2, 1, 4
The 2nd shuffle：4, 2, 3, 5, 1
The 3rd shuffle：1, 3, 2, 4, 5
The 4th shuffle：5, 2, 3, 1, 4
The 5th shuffle：4, 3, 2, 5, 1
The 6th shuffle：1, 2, 3, 4, 5(the same as it is in the beginning)

You'll find that after six shuffles, the cards' order returns the beginning. In fact, there is always a number m for any case of shuffling that the cards' order returns the beginning after m shuffles. Now your task is to find the shuffle with the largest m. If there is not only one, sort out the one with the smallest order.

Input

The first line of the input is an integer T which indicates the number of test cases. Each test case occupies a line, contains an integer n (1 ≤ n ≤ 100).

Output

Each test case takes a line, with an integer m in the head, following the case of shuffling.

Sample Input

```2
1
5
```

Sample Output

```1 1
6 2 1 4 5 3
```

Source

[Submit]   [Go Back]   [Status]   [Discuss]