This page is still under construction.

Parts of this page are still being built. What you see may change.

Order

Interview

Time limit1sMemory limit128 MB

Summary
Recover the permutation from counts of smaller previous elements, printing IMPOSSIBLE when the counts allow no permutation.
Level

Medium5 of 10

Topics
Simulation, Math
Solved
No attempts yet

Problem

There is a sequence S=(s1,s2,…,sn)S = (s_1, s_2, \dots, s_n) made up of nn distinct integers. It is a permutation that uses each integer from 11 to nn exactly once, so si≠sjs_i \ne s_j for every i≠ji \ne j and 1≤si≤n1 \le s_i \le n.

From SS we can build a new sequence R=(r1,r2,…,rn)R = (r_1, r_2, \dots, r_n), where rir_i is the number of elements among those that come before sis_i, namely {s1,s2,…,si−1}\{s_1, s_2, \dots, s_{i-1}\}, that are smaller than sis_i.

For example, if n=10n = 10 and S=(6,4,3,5,1,2,7,8,9,10)S = (6, 4, 3, 5, 1, 2, 7, 8, 9, 10), then R=(0,0,0,2,0,1,6,7,8,9)R = (0, 0, 0, 2, 0, 1, 6, 7, 8, 9).

Given a sequence RR, write a program that recovers the original sequence SS. If an SS corresponding to RR exists, it is uniquely determined, but for some inputs no such SS exists. For example, if n=5n = 5 and R=(0,2,2,0,1)R = (0, 2, 2, 0, 1), then no SS corresponds to this RR.

Input

Input is read from standard input. The first line contains the number of test cases TT. Each test case consists of two lines: the first line contains the length of the sequence nn (1≤n≤1001 \le n \le 100), and the second line contains the nn integers r1,r2,…,rnr_1, r_2, \dots, r_n of the sequence RR, separated by spaces.

Output

For each test case, print the sequence SS corresponding to the given RR on one line, with its numbers separated by spaces. If SS cannot be recovered from RR, print IMPOSSIBLE on that line instead.

Examples3

  1. Example 1

    Input
    3
    10
    0 0 0 2 0 1 6 7 6 9
    10
    0 0 0 0 0 0 0 0 0 0
    12
    0 3 4 5 0 1 2 3 4 5 6 7
    
    Expected output
    6 4 3 5 1 2 8 9 7 10
    10 9 8 7 6 5 4 3 2 1
    IMPOSSIBLE
    
  2. Example 2

    Input
    1
    5
    0 1 2 3 4
    
    Expected output
    1 2 3 4 5
    
  3. Example 3

    Input
    1
    5
    0 0 0 0 0
    
    Expected output
    5 4 3 2 1