Consider the following scheme: for permuting a string of letters: first we create all different rotations of the string, then we sort them in lexicographical order, and finally we take the last letter of each rotation and concatenate them to form a new string.
For the string "LEIDEN.", for example, the seven rotation in lexicographical order are(where the period '.' comes before any letter):
.LEIDENso this results in the string "NILDE.E"
DEN.LEI
EIDEN.L
EN.LEID
IDEN.LE
LEIDEN.
N.LEIDE
The first line of the input contains a single number: the number of test cases to follow. Each test case has the following format:
One line with the compressed string.This string will consist of uppercase letters, numbers and a single period, and will be a valid block compressed string. The length of the original string that resulted in the compressed one will be no more then 1000000 characters.
For every test case in the input, the output should contain a single line with the decompressed string.
3 NILDE.E N13.E13 LRSGORTNOMOMAIOSROC2.GAPTE2NS
LEIDEN. ENENENENENENENENENENENENEN. PROGRAMMINGCONTESTSARESOCOOL.
Migrated from old NTUJ.
No. | Testdata Range | Score |
---|