Suffix Array Reconstruction

No attempts yetTime limit1sMemory limit512 MB

Problem

Given a text s[1..n]s[1..n] of length nn, form all of its suffixes

s[1..n], s[2..n], , s[n..n]s[1..n],\ s[2..n],\ \ldots,\ s[n..n]

and sort them lexicographically to obtain the sorted list

s[p(1)..n], s[p(2)..n], , s[p(n)..n].s[p(1)..n],\ s[p(2)..n],\ \ldots,\ s[p(n)..n].

The sequence p(1),p(2),,p(n)p(1), p(2), \ldots, p(n) is called the suffix array of ss. For example, if s=abbaababs = \texttt{abbaabab}, sorting all suffixes lexicographically gives

aabab, ab, abab, abbaabab, b, baabab, bab, bbaabab

so the suffix array is 4,7,5,1,8,3,6,24, 7, 5, 1, 8, 3, 6, 2.

Your task is the inverse. Given a sequence p(1),p(2),,p(n)p(1), p(2), \ldots, p(n) (a permutation of 11 through nn), decide whether there exists a text over lowercase English letters whose suffix array is exactly this sequence, and if so reconstruct such a text.

Input

The first line contains the number of test cases tt (1t1001 \le t \le 100). Each test case consists of two lines: the first contains the length nn (1n5000001 \le n \le 500000) of both the text and the array, and the second contains the nn integers p(1),p(2),,p(n)p(1), p(2), \ldots, p(n). It is guaranteed that 1p(i)n1 \le p(i) \le n and that no value occurs twice (so pp is a permutation of 1..n1..n). The total size of the input does not exceed 50 MB.

Output

For each test case, if some text over lowercase English letters (az) has pp as its suffix array, output the lexicographically smallest such text on its own line. Otherwise output -1.