problems / 221

Alice's Secret Santa

easy constructive math 1000 ms · 256 MB

Alice's Secret Santa

Alice is organising a Secret Santa party for n friends, numbered from 1 to n (Alice and Bob among them). Every friend buys exactly one gift and hands it to exactly one other friend, and every friend receives exactly one gift. Nobody may give a gift to themselves. Last year Bob gave Alice a gift and Alice gave Bob one right back, and everybody agreed that was dull, so this year no two friends may give gifts to each other.

Formally, find a sequence p_1, p_2, …, p_n, where friend i gives a gift to friend p_i, such that:

  • every number from 1 to n appears in the sequence exactly once;
  • p_i ≠ i for every i;
  • there are no two friends i ≠ j with p_i = j and p_j = i.

Help Alice, or tell her that no such plan exists.

Input

The first line contains t (1 ≤ t ≤ 10^4), the number of parties.

Each of the next t lines contains one integer n (1 ≤ n ≤ 2·10^5), the number of friends at that party. The sum of n over all parties does not exceed 2·10^5.

Output

For each party, print one line. If a plan exists, print n integers p_1, p_2, …, p_n separated by spaces. Otherwise print -1.

If there are several valid plans, print any of them.

Notes

In the first example, with 4 friends: friend 1 gives to friend 2, friend 2 to friend 3, friend 3 to friend 4 and friend 4 to friend 1. Nobody gives to themselves and no two friends exchange gifts with each other. Other plans, such as 3 4 2 1, are also accepted.

With 1 friend there is nobody to give a gift to, and with 2 friends each one has to give to the other, which is not allowed, so both answers are -1.

Any correct answer is accepted.

Example 1

Input

3
4
1
2

Output

2 3 4 1
-1
-1

Example 2

Input

2
3
5

Output

2 3 1
2 3 4 5 1

Hints · reveal one at a time if you're stuck

Hint 1

Try the smallest parties by hand: which values of n have no valid plan at all?

Hint 2

Imagine the friends sitting around a round table. Is there a simple rule for passing gifts that never sends a gift straight back to the person it came from?

report an issue Prefer your own editor? sooks prep 221 (CLI)
Sign in to run code

Run your code on the examples, or submit it against every test.