You are given an array $$$A$$$ of length $$$n$$$, where the array uses one-based indexing (i.e., the elements are $$$A[1], A[2], \dots, A[n]$$$).
Define the following function:
Function F(i, n, A):
Reverse(A[1..i]) // Reverse the prefix of length i
ret ← 0
For j ← 1 to n:
ret ← ret + (j × A[j]) // weighted sum
Return ret
That is, the function reverses the prefix of the array from index $$$1$$$ to $$$i$$$ and then computes the weighted sum.
The function operates on a temporary copy of the array $$$A$$$. That is,
For the given array $$$A$$$, consider all values $$$F(i, n, A)$$$ for $$$1 \le i \le n$$$. Your task is to output an ordering of indices $$$[p_1, p_2, \dots, p_n]$$$ which is a permutation of $$$\{1, 2, \dots, n\}$$$, such that:
The problem contains multiple test cases. The first line contains the number of test cases $$$t$$$ $$$(1 \le t\le 10^4)$$$. The description of the test cases follows:
For each testcase, output the ordering in a single line separated by spaces.
250 -1 2 3 -451 0 1 0 -1
4 3 1 2 51 3 2 4 5
For the first array, the values of the function are:
Sorting the indices by non-decreasing values of $$$F(i, 5, A)$$$ gives the ordering: $$$[4 \; 3 \; 1 \; 2 \; 5]$$$
For the second array, there are two valid orderings that satisfy the constraints:
Among these, we output $$$[1 \; 3 \; 2 \; 4 \; 5]$$$ as it is the lexicographically smallest valid ordering.