beecrowd | 2020

Elves and Their Codes

By Lucas Bucior, beecrowd BR Brazil

Timelimit: 1

This year Santa Claus received several lists of gifts, requests and more applications to make, all lists are encoded by elves. As there are thousands of lists and Santa is organized, decided to ask for your help, how does he know that you are dedicated and you know the standard decoding of the elves, released 26 gnomes and goblins 676. Each list is decoded through collaboration of gnomes and elves helpers of Santa Claus. The gnomes are listed from 1 to 26 and for each Gnome, 26 goblins that correspond to letters from A to Z (including the letters K, W, Y). When the decoding is initiated, every N rows are performed. Each line corresponds to a gift. Follow the steps to decode a given list created by Elves:

    1st The gnomes are organized representing lines and the goblins are organized representing the columns.

    2nd For each gnome, is found a goblin. For example if the integer i is 2 (line 2) the gnome is 2, the goblin is also 2, therefore corresponds to character B.

    3rd All the elves, at the gnome position should be moved to the end.

    4th The gnome line must be moved to the last valid position.

    For the next integer number, note that if it is 2 (line 2) the gnome now is 3, as well the Elf (3), therefore corresponding to the character D.

The first step is to run each new hard-coded list for elves, the 2nd, 3rd and 4th step are performed for each integer i corresponds to the row of the matrix. Let Santa know the gifts that contains the encoded list by elves.


The first line of each test case contains an integer N (1 ≤ N≤ 10000), that corresponds to the number of lines coded by elves. The N lines contains an indefinite number of integers i (1 ≤ i ≤ 27), each integer i represents the row of the array, and if i is 27, a space. The entry ends with end-of-file (EOF).


For each list encoded by elves, you must submit the message “LISTA #X:”, where X is the number of the list following the sequence (1, 2, 3, ...), then you must list all alphabetically and capital gifts, one in each line. Print a blank line between two consecutive test cases. At the end of the exit there should be a blank line.

Input Sample Output Sample

13 1 10 3 12 18 27 2 25 27 22 7 5 23 24
18 5 10 11 5 5 18
22 15 14 19 19 5 13
3 1 11 9 21 17 25 25
17 10 22 21 18 22 24 24
21 25 17 21 20 23 22
26 17 21 26 11 20 18 9
6 24 22 26 25 22 25