#include <bits/stdc++.h>
using namespace std;
string operation1(string s){
return s;
}
string operation2(string s){
string temp = s;
reverse(s.begin(), s.end());
string temp2 = s + temp;
return temp2;
}
int main() {
int t; cin >> t;
while(t--){
int n; cin >> n;
string s; cin >> s; int len = s.length();
string final1 = operation1(s);
string final2 = operation2(s);
int x = 0;
for(int i=0; i<s.length(); i++){
if(final1[i] < final2[i]){
x = 1;
break;
}
else if(final1[i] > final2[i]){
x=2;
break;
}
}
if(x == 0)cout << final1 << endl;
else if(x == 1) cout << final1 << endl;
else if(x==2) cout << final2 << endl;
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgpzdHJpbmcgb3BlcmF0aW9uMShzdHJpbmcgcyl7CglyZXR1cm4gczsKfQoKc3RyaW5nIG9wZXJhdGlvbjIoc3RyaW5nIHMpewoJc3RyaW5nIHRlbXAgPSBzOwoJcmV2ZXJzZShzLmJlZ2luKCksIHMuZW5kKCkpOwoJc3RyaW5nIHRlbXAyID0gcyArIHRlbXA7CglyZXR1cm4gdGVtcDI7Cn0KCgppbnQgbWFpbigpIHsKCWludCB0OyBjaW4gPj4gdDsKCXdoaWxlKHQtLSl7CgkJaW50IG47IGNpbiA+PiBuOwoJCXN0cmluZyBzOyBjaW4gPj4gczsgaW50IGxlbiA9IHMubGVuZ3RoKCk7CgkJc3RyaW5nIGZpbmFsMSA9IG9wZXJhdGlvbjEocyk7CgkJc3RyaW5nIGZpbmFsMiA9IG9wZXJhdGlvbjIocyk7CgkJaW50IHggPSAwOwoJCWZvcihpbnQgaT0wOyBpPHMubGVuZ3RoKCk7IGkrKyl7CgkJCWlmKGZpbmFsMVtpXSA8IGZpbmFsMltpXSl7CgkJCQl4ID0gMTsKCQkJCWJyZWFrOwoJCQl9CgkJCWVsc2UgaWYoZmluYWwxW2ldID4gZmluYWwyW2ldKXsKCQkJCXg9MjsKCQkJCWJyZWFrOwoJCQl9CgkJfQoJCWlmKHggPT0gMCljb3V0IDw8IGZpbmFsMSA8PCBlbmRsOwoJCWVsc2UgaWYoeCA9PSAxKSBjb3V0IDw8IGZpbmFsMSA8PCBlbmRsOwoJCWVsc2UgaWYoeD09MikgY291dCA8PCBmaW5hbDIgPDwgZW5kbDsKCX0KCXJldHVybiAwOwp9