FIICode 2025 Qualifying Round - Studenți | No More Threes

This was the problem page during the contest. Access the current page here.
Time limit: 1s Memory limit: 256MB Input: Output:

 

Task

You are given an array aa of length nn.

Find any array bb of length nn which satisfies all of the following conditions:

  • [b1,b2,,bn][b_1,b_2,\ldots,b_n] is a permutation1^1 of [a1,a2,,an][a_1,a_2,\ldots,a_n];
  • For all ii (1in1 \le i \le n), b1+b2+b3++bib_1+b_2+b_3+\ldots+b_i is not divisibile by 33.

If no such array exists, print -1 instead.

1^1An array [b1,b2,,bn][b_1,b_2,\ldots,b_n] is a permutation of another array [a1,a2,,an][a_1,a_2,\ldots,a_n] if bb contains the same elements as aa, but potentially in another order. For example, [1,2,3,3][1,2,3,3] is a permutation of [3,2,3,1][3,2,3,1], but [3,2,3,1][3,2,3,1] is not a permutation of [2,2,3,1][2,2,3,1].

Input data

Each test contains multiple test cases. The first line of input contains a single integer tt (1t1041 \le t \le 10^4) - the number of test cases. The next lines contain the descriptions of the test cases.

The first line of each test case contains a single integer nn (1n1051 \le n \le 10^5) - the length of array aa.

The second line of each test case contains nn integers a1,a2,,ana_1,a_2,\ldots,a_n (1ai1091 \le a_i \le 10^9) - the elements of array aa.

It is guaranteed that the sum of nn across all test cases does not exceed 51055 \cdot 10^5.

Output data

For each test case, print any array [b1,b2,,bn][b_1,b_2,\ldots,b_n] which satisfies all of the conditions from the statement.

If no such arrays exist, print -1 instead.

Example

stdin

7
1
1
4
2 2 2 2
5
1 2 3 1 2
6
8 7 8 9 7 4
7
2 3 4 5 6 7 8
8
8 1 2 7 7 9 6 10
9
6 11 4 5 8 9 11 3 4

stdout

1
-1
-1
4 7 8 9 7 8
8 2 3 4 5 6 7
10 9 1 8 6 7 2 7
11 3 11 6 9 4 5 4 8

Explanation

In the first test case, b=[1]b=[1] is a valid permutation of a=[1]a=[1], since:

  • b1=1b_1=1, which is not divisible by 33.

We can show that there are no solutions for the second and third test cases.

In the fourth test case, b=[4,7,8,9,7,8]b=[4,7,8,9,7,8] is a valid permutation of a=[8,7,8,9,7,4]a=[8,7,8,9,7,4], since:

  • b1=4b_1=4, which is not divisible by 33.
  • b1+b2=4+7=11b_1+b_2=4+7=11, which is not divisible by 33.
  • b1+b2+b3=4+7+8=19b_1+b_2+b_3=4+7+8=19, which is not divisible by 33.
  • b1+b2+b3+b4=4+7+8+9=28b_1+b_2+b_3+b_4=4+7+8+9=28, which is not divisible by 33.
  • b1+b2+b3+b4+b5=4+7+8+9+7=35b_1+b_2+b_3+b_4+b_5=4+7+8+9+7=35, which is not divisible by 33.
  • b1+b2+b3+b4+b5+b6=4+7+8+9+7+8=43b_1+b_2+b_3+b_4+b_5+b_6=4+7+8+9+7+8=43, which is not divisible by 33.

Log in or sign up to be able to send submissions!