Chefs and Voting for best friend

All submissions for this problem are available.
Read problems statements in Mandarin Chinese , Russian and Vietnamese
There are n chef's in Chefland. There is a festival in Chefland in which each chef is asked to vote a person as his best friend. Obviously, a person can't vote himself as his best friend. Note that the best friend relationship is not necessarily bidirectional, i.e. it might be possible that x is best friend of y, but y is not a best friend of x.
Devu was the election commissioner who conducted this voting. Unfortunately, he was sleeping during the voting time. So, he could not see the actual vote of each person, instead after the voting, he counted the number of votes of each person and found that number of votes of ith person was equal to c_{i}.
Now he is wondering whether this distribution of votes corresponds to some actual voting or some fraudulent voting has happened. If the current distribution of votes does not correspond to any real voting, print 1. Otherwise, print any one of the possible voting which might have lead to the current distribution. If there are more than one possible ways of voting leading to the current distribution, you can print any one of them.
Input
 First line of the input contains a single integer T denoting number of test cases.
 First line of each test case, contains a single integer n.
 Second line of each test case, contains n space separated integers denoting array c.
Output
For each test case, If there is no real voting corresponding to given distribution of votes, print 1 in a single line.
 Otherwise, print n space separated integers denoting a possible voting leading to current distribution of votes. ith integer should denote the index of the person (1 based indexing) whom ith person has voted as his best friend.
Constraints and Subtasks
 1 ≤ T ≤ 500
 1 ≤ n ≤ 50
 0 ≤ c_{i} ≤ n
Example
Input: 3 3 1 1 1 3 3 0 0 3 2 2 0 Output: 2 3 1 1 1
Explanation
Example 1: In this example, each person has received one vote. One possible example of real voting leading to this distribution is {2, 3, 1}. In this distribution, number of votes of all three persons are equal to 1. Also it is real voting because no person votes himself as his best friend. You can also output another possible distribution {3, 1, 2} too.
Example 2: There is no real voting corresponding to this voting distribution.
Example 3: There is no real voting corresponding to this voting distribution.
Author:  admin2 
Editorial  http://discuss.codechef.com/problems/CHEFVOTE 
Tags  adhoc, admin2, digraph, graph, realization, snck151a 
Date Added:  20052015 
Time Limit:  1 sec 
Source Limit:  50000 Bytes 
Languages:  C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, SCALA, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, PERL6, TEXT, SCM chicken, CLOJ, FS 
Comments
 Please login at the top to post a comment.
SUCCESSFUL SUBMISSIONS
Fetching successful submissions
HELP
If you are still having problems, see a sample solution here. 