Datasets:

Modalities:
Image
Text
Formats:
parquet
Size:
< 1K
Tags:
code
Libraries:
Datasets
pandas
License:
File size: 2,180 Bytes
7acee6b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
Many people are avid fans of the daily crossword in the paper, but not you. I
mean, the format is pretty terrible, right? You only get to use English words,
and any hack can look those up in a dictionary. Also, it takes forever to make
just one puzzle. What a waste of time.

You've written a letter to the editor describing a new word game. It's really
easy to make new puzzles because the only thing you give the solver is a
permutation **P1..N** of the first **N** positive integers. It's then up to
the solver to find any string that's _salient_ for the given permutation.

A string is _salient_ for the permutation **P1..N** if it consists of **N**
uppercase letters ("A"..."Z"), such that when its **N** non-empty suffixes are
sorted in lexicographical order, the suffix starting at the _i_th character is
the **Pi**th suffix in the sorted list. It's possible that a given permutation
has no salient strings.

You need some example puzzles to include in your letter. You already have some
permutations generated, so all you need is to supply an answer for each
permutation (if possible).

### Input

Input begins with an integer **T**, the number of different permutations
you've generated. For each permutation, there is first a line containing the
integer **N**. Then **N** lines follow, the _i_th of which contains the
integer **Pi**. It is guaranteed that each integer from 1 to **N** shows up
exactly once in **P**.

### Output

For the _i_th permutation, print a line containing "Case #**i**: " followed by
any salient string for that permutation (note that any valid string consisting
of **N** uppercase letters will be accepted), or "-1" if there are no such
strings.

### Constraints

1 ≤ **T** ≤ 2,000  
1 ≤ **N** ≤ 1,000  
1 ≤ **Pi****N**  

### Explanation of Sample

In the first case, if we sort the suffixes of FACEBOOK we get:

  1. ACEBOOK 
  2. BOOK 
  3. CEBOOK 
  4. EBOOK 
  5. FACEBOOK 
  6. K 
  7. OK 
  8. OOK 
If we read the indices of the suffixes back in order of decreasing length, we
get 5 1 3 4 2 8 7 6, which is the given permutation. Therefore "FACEBOOK" is
salient for this permutation, and is one possible accepted answer.