#K44307. Deranged Array Generation

    ID: 27502 Type: Default 1000ms 256MiB

Deranged Array Generation

Deranged Array Generation

You are given an array of n distinct integers. Your task is to generate a derangement of the given array such that no element remains in its original position. In other words, if the original array is a and the deranged array is b, then for every index i (1 ≤ i ≤ n), it must hold that:

$$b_i \neq a_i$$

If there are multiple valid derangements, you may output any one of them. It is guaranteed that n ≥ 2 for every test case.

inputFormat

The first line of input contains an integer T representing the number of test cases. Each test case consists of two lines. The first line contains an integer n (with n ≥ 2), and the second line contains n space-separated integers representing the array.

Example:

2
3
1 2 3
4
4 5 6 7

outputFormat

For each test case, output a single line containing a deranged array of n integers. The deranged array must satisfy the condition that for every index i, the element at position i in the output array is not equal to the element at position i in the input array.

Example:

2 3 1
5 4 7 6
## sample
1
3
1 2 3
2 3 1

</p>