← Home
write a go solution for Description:
Farmer John has a permutation p_1,p_2,ldots,p_n, where every integer from 0 to n-1 occurs exactly once. He gives Bessie an array a of length n and challenges her to construct p based on a.

The array a is constructed so that a_i = textttMEX(p_1,p_2,ldots,p_i)-p_i, where the textttMEX of an array is the minimum non-negative integer that does not appear in that array. For example, textttMEX(1,2,3)=0 and textttMEX(3,1,0)=2.

Help Bessie construct any valid permutation p that satisfies a. The input is given in such a way that at least one valid p exists. If there are multiple possible p, it is enough to print one of them.

Input Format:
The first line contains t (1<=t<=10^4) — the number of test cases.

The first line of each test case contains an integer n (1<=n<=2*10^5) — the lengths of p and a.

The second line of each test case contains n integers a_1,a_2,ldots,a_n (-n<=a_i<=n) — the elements of array a.

It is guaranteed that there is at least one valid p for the given data.

It is guaranteed that the sum of n over all test cases does not exceed 2*10^5.

Output Format:
For each test case, output n integers on a new line, the elements of p.

If there are multiple solutions, print any of them.

Note:
In the first case, p=[0,1,4,2,3] is one possible output.

a will then be calculated as a_1=textttMEX(0)-0=1, a_2=textttMEX(0,1)-1=1, a_3=textttMEX(0,1,4)-4=-2, a_4=textttMEX(0,1,4,2)-2=1, a_5=textttMEX(0,1,4,2,3)-3=2.

So, as required, a will be [1,1,-2,1,2].. Output only the code with no comments, explanation, or additional text.