#include <iostream>#include <string>#include <fstream>#include <vector>#include <algorithm>usingnamespacestd;
voidsolve(strings);
intmain()
{
#ifndef ONLINE_JUDGEifstreamfin("d:\\OJ\\uva_in.txt");
streambuf*old=cin.rdbuf(fin.rdbuf());
#endifintt;
cin>>t;
while (t--) {
strings;
cin>>s;
solve(s);
}
#ifndef ONLINE_JUDGEcin.rdbuf(old);
#endifreturn0;
}
voidsolve(strings)
{
vector<string>vStr;
vStr.push_back(s);
for (size_ti=1, len=s.length(); i<len; i++) {
stringtmp;
tmp.append(s, i, len-i);
tmp.append(s, 0, i);
vStr.push_back(tmp);
}
sort(vStr.begin(), vStr.end());
cout<<vStr.front() <<endl;
}