Penchick loves two things: square numbers and Hong Kong-style BBQ buns! For his…
- User
Penchick loves two things: square numbers and Hong Kong-style BBQ buns! For his birthday, Kohane wants to combine them with a gift: 𝑛 BBQ buns arranged from left to right. There are 106 available fillings of BBQ buns, numbered from 1 to 106 . To ensure that Penchick would love this gift, Kohane has a few goals:
No filling is used exactly once; that is, each filling must either not appear at all or appear at least twice. For any two buns 𝑖 and 𝑗 that have the same filling, the distance between them, which is |𝑖−𝑗| , must be a perfect square∗ . Help Kohane find a valid way to choose the filling of the buns, or determine if it is impossible to satisfy her goals!
∗ A positive integer 𝑥 is a perfect square if there exists a positive integer 𝑦 such that 𝑥=𝑦2 . For example, 49 and 1 are perfect squares because 49=72 and 1=12 respectively. On the other hand, 5 is not a perfect square as no integer squared equals 5
Input Each test contains multiple test cases. The first line contains the number of test cases 𝑡 (1≤𝑡≤2⋅105 ). The description of the test cases follows.
The only line of each test case contains a single integer 𝑛 (1≤𝑛≤2⋅105 ) — the number of BBQ buns.
It is guaranteed that the sum of 𝑛 over all test cases does not exceed 2⋅105 .
Output For each test case, if no valid choice of fillings exists, output −1 . Otherwise, output 𝑛 integers, where the 𝑖 -th integer represents the filling of the 𝑖 -th BBQ bun.
Example InputCopy 2 3 12 OutputCopy -1 1 2 3 6 10 2 7 6 10 1 7 3 Note In the first test case, the choice of fillings "1 1 1" is not allowed because buns 1 and 3 have the same filling, but are distance 2 apart, which is not a perfect square. The choice of fillings "1 1 2" is also not allowed as filling 2 is only used once.
In the second test case, the solution is valid because no filling is used exactly once, and any two buns with the same filling are spaced at a distance equal to a perfect square. For example, buns 1 and 10 both have filling 1 and are spaced at a distance of 9=32 . Similarly, buns 5 and 9 both have filling 10 and are spaced at a distance of 4=22 .
- Assistant
To solve the problem, we need to assign fillings to BBQ buns in such a way that:
- Each filling is used either zero times or at least twice.
- For any two buns with the same filling, the distance between them (i.e., the absolute difference in their positions) must be a perfect square.