Permutation

Given N and K find the N-th permutation of the integers from 1 to K when those permutations are lexicographically ordered. N starts from 0. Since N is very large N will be represented by a sequence of K non-negative integers S1, S2, ..., Sk. From this sequence of integers N can be calculated with the following expression. Input ∑K Si ∗ (K − i)! i=1 First line of the input contains T (≤ 10) the number of test cases. Each of these test cases consists of 2 lines. First line contains a integer K (1 ≤ K ≤ 50000). Next line contains K integers S1, S2, ..., Sk. (0≤Si ≤K−i). Output For each test case output contains N-th permutation of the integers from 1 to K. These K integers should be separated by a single space. Sample Input 4 3 210 3 100 4 2110 4 1210 Sample Output 321 213 3241 2431