267 传统题

[CF2290F] 还原排列 (Reconstruct Permutation)

时间限制
2000ms
内存限制
256MiB
登顶 / 尝试
0/ 0
难度
4

[CF2290F] 还原排列 (Reconstruct Permutation)

Problem Statement

For a permutation pp of length nn, define an array b1,b2,…,bnb_1, b_2, \dots, b_n as follows:

Initially, bx=0b_x = 0 for all 1≤x≤n1 \le x \le n. For every pair of values (x,y)(x, y) with 1≤x<y≤n1 \le x < y \le n such that xx appears to the left of yy in pp, perform:

  • subtract 11 from bxb_x;
  • add 11 to byb_y.

Note that bb is indexed by the values themselves, not by positions.

Given b1,b2,…,bnb_1, b_2, \dots, b_n, reconstruct a permutation pp that produces this array bb, or report -1 if no such permutation exists. It can be proved that if such a permutation exists, it is unique.

Input

The first line contains tt (1≤t≤1041 \le t \le 10^4) — the number of test cases.

Each test case consists of nn (1≤n≤2⋅1051 \le n \le 2 \cdot 10^5) on the first line, and nn integers b1,b2,…,bnb_1, b_2, \dots, b_n (−n≤bx≤n-n \le b_x \le n) on the second line.

It is guaranteed that the sum of nn over all test cases does not exceed 2⋅1052 \cdot 10^5.

Output

For each test case, print -1 if no valid permutation exists; otherwise print nn integers p1,p2,…,pnp_1, p_2, \dots, p_n.

Example

5
3
0 -1 1
1
0
2
1 1
4
-2 1 -1 2
3
-1 0 1
2 3 1
1
-1
3 1 4 2
-1

Note

  • Constraints: 1≤t≤1041 \le t \le 10^4, 1≤n≤2⋅1051 \le n \le 2 \cdot 10^5, −n≤bx≤n-n \le b_x \le n, ∑n≤2⋅105\sum n \le 2 \cdot 10^5.
  • Source: Codeforces 2290F · Reconstruct Permutation