Largest Number

All submissions for this problem are available.
Aditi and Aastik are busy preparing brainteasers for Todo En Uno. They think of many puzzles, but none seem satisfactory. Defeated, they seek the help of their juniors. One of them comes up with an interesting question. For any positive integer, we can change the position of first and last digit of a number by either moving the first digit to the end of the number , or the last digit to the front of the number . For example, the number 12345 could be changed to 23451 or 51234. If there are any leading zeros after performing such an operation , they must be removed. So 10203 will become 2031 if we move first two digits to the end , then changed to 312 on further such operation. Given an integer N, determine the largest integer that can result from performing a series of one or more operations on N.
Input
Input will begin with an integer T (at most 1000), the number of test cases.
Each test case consists of a positive integer N<100000000 (10^8)
Output
For each test case, print the largest integer that can result from performing one or more such operations on N.
Constraints
N<100000000 (10^8)
Example
Input: 5 12345 98765 109001 5 10 Output: 51234 98765 110900 5 1
Explanation
Example case 5. Ans is 1 because you must perform atleast one rotation.
Author:  sachit007 
Tags  sachit007 
Date Added:  28012015 
Time Limit:  1 sec 
Source Limit:  50000 Bytes 
Languages:  C, CPP14, JAVA, PYTH, PYTH 3.5, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, 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 
Comments
 Please login at the top to post a comment.
SUCCESSFUL SUBMISSIONS
Fetching successful submissions
HELP
If you are still having problems, see a sample solution here. 