#include <bits/stdc++.h>
using namespace std;
string makeString(string s, int k){
for(int i = 0; i < (int)s.size() - k + 1; ++i){
reverse(s.begin() + i, s.begin() + i + k);
}
return s;
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t, n;
string s;
cin >> t;
while(t--){
cin >> n >> s;
if(n == 1){
cout << s << '\n' << 1 << '\n';
continue;
}
bool ok = true;
char mn = s[0];
for(int i = 1; i < n; ++i){
if(mn != s[i]){
ok = false;
}
if(mn > s[i]){
mn = s[i];
}
}
if(ok){
cout << s << '\n' << 1 << '\n';
continue;
}
string small = s;
int k = 1;
for(int i = 0; i < n; ++i){
if(s[i] == mn){
string now = makeString(s, i + 1);
if(now < small && i + 1 > k){
small = now;
k = i + 1;
}
}
}
cout << small << '\n' << k << '\n';
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgpzdHJpbmcgbWFrZVN0cmluZyhzdHJpbmcgcywgaW50IGspewogICAgZm9yKGludCBpID0gMDsgaSA8IChpbnQpcy5zaXplKCkgLSBrICsgMTsgKytpKXsKICAgICAgICByZXZlcnNlKHMuYmVnaW4oKSArIGksIHMuYmVnaW4oKSArIGkgKyBrKTsKICAgIH0KICAgIHJldHVybiBzOwp9CgppbnQgbWFpbigpewoKICAgIGlvczo6c3luY193aXRoX3N0ZGlvKDApOwogICAgY2luLnRpZSgwKTsKICAgIGNvdXQudGllKDApOwoKICAgIGludCB0LCBuOwogICAgc3RyaW5nIHM7CiAgICBjaW4gPj4gdDsKICAgIHdoaWxlKHQtLSl7CiAgICAgICAgY2luID4+IG4gPj4gczsKICAgICAgICBpZihuID09IDEpewogICAgICAgICAgICBjb3V0IDw8IHMgPDwgJ1xuJyA8PCAxIDw8ICdcbic7CiAgICAgICAgICAgIGNvbnRpbnVlOwogICAgICAgIH0KICAgICAgICBib29sIG9rID0gdHJ1ZTsKICAgICAgICBjaGFyIG1uID0gc1swXTsKICAgICAgICBmb3IoaW50IGkgPSAxOyBpIDwgbjsgKytpKXsKICAgICAgICAgICAgaWYobW4gIT0gc1tpXSl7CiAgICAgICAgICAgICAgICBvayA9IGZhbHNlOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmKG1uID4gc1tpXSl7CiAgICAgICAgICAgICAgICBtbiA9IHNbaV07CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgaWYob2spewogICAgICAgICAgICBjb3V0IDw8IHMgPDwgJ1xuJyA8PCAxIDw8ICdcbic7CiAgICAgICAgICAgIGNvbnRpbnVlOwogICAgICAgIH0KICAgICAgICBzdHJpbmcgc21hbGwgPSBzOwogICAgICAgIGludCBrID0gMTsKICAgICAgICBmb3IoaW50IGkgPSAwOyBpIDwgbjsgKytpKXsKICAgICAgICAgICAgaWYoc1tpXSA9PSBtbil7CiAgICAgICAgICAgICAgICBzdHJpbmcgbm93ID0gbWFrZVN0cmluZyhzLCBpICsgMSk7CiAgICAgICAgICAgICAgICBpZihub3cgPCBzbWFsbCAmJiBpICsgMSA+IGspewogICAgICAgICAgICAgICAgICAgIHNtYWxsID0gbm93OwogICAgICAgICAgICAgICAgICAgIGsgPSBpICsgMTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBjb3V0IDw8IHNtYWxsIDw8ICdcbicgPDwgayA8PCAnXG4nOwogICAgfQogICAgcmV0dXJuIDA7Cn0K