Jadu and his fortune telling device
Jadu the famous coder of codeland wants to crack the password of MATA, the great fortune telling device which is owned by his enemy Billa. Billa being over-confident hands over a string 's' to Jadu, and challenges him to find the lexicographically smallest string considering the string is circular (i.e. the element next to the last element is the first element) and of the same length as the original string 's'. Only clockwise rotation is allowed.
First line contains 't' denoting the number of test-cases. Next 't' lines contains a string 's'.
Output 't' lines printing the required string.
- 1<=Length of string<=1000
- All the characters in the string are lowercase english alphabets. Each alphabet in the string doesn't occur more than 100 times.
Input: 2 abaca bcadz Output:
Example case 1-if the string 's' is 'abaca' with indexing [1,2,3,4,5] then the answer of the above query will be 'aabac' with indexing [5,1,2,3,4].
Example case 2-For 'bcadz' with indexing [1,2,3,4,5] the answer will be 'adzbc' with indexing [3,4,5,1,2].
|Time Limit:||1 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, PAS fpc, PAS gpc, RUBY, PHP, NODEJS, HASK, SCALA, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, PERL6, TEXT, SCM chicken, CLOJ, FS|
Fetching successful submissions