#include <bits/stdc++.h>
using namespace std;
int main(){
int t;
cin >> t;
while (t--){
string s;
int length;
cin >> length >> s;
unordered_map<char, int> hash;
for(int i = 0; i < s.length(); i++){
hash[s[i]]++;
}
int max_count = 0, res = -1;
int min_count = 11, tres = -1;
for (auto i : hash) {
if (max_count < i.second) {
res = i.first;
max_count = i.second;
}
if (min_count > i.second) {
tres = i.first;
min_count = i.second;
}
}
if (max_count == min_count){
res = s[0];
for(int j = 1; j < s.length(); j++){
if(s[j] != res){
s[j] = res;
break;
}
}
}
else{
size_t pos = s.find(tres);
s[pos] = char(res);
}
cout << s << endl;
}
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgppbnQgbWFpbigpewoJaW50IHQ7CgljaW4gPj4gdDsKCXdoaWxlICh0LS0pewoJCXN0cmluZyBzOwoJCWludCBsZW5ndGg7CgkJY2luID4+IGxlbmd0aCA+PiBzOwoJCXVub3JkZXJlZF9tYXA8Y2hhciwgaW50PiBoYXNoOwoJCWZvcihpbnQgaSA9IDA7IGkgPCBzLmxlbmd0aCgpOyBpKyspewoJCQloYXNoW3NbaV1dKys7CgkJfQoJCWludCBtYXhfY291bnQgPSAwLCByZXMgPSAtMTsKCQlpbnQgbWluX2NvdW50ID0gMTEsIHRyZXMgPSAtMTsKICAgIAlmb3IgKGF1dG8gaSA6IGhhc2gpIHsKICAgICAgICBpZiAobWF4X2NvdW50IDwgaS5zZWNvbmQpIHsKICAgICAgICAgICAgcmVzID0gaS5maXJzdDsKICAgICAgICAgICAgbWF4X2NvdW50ID0gaS5zZWNvbmQ7CiAgICAgICAgCX0KICAgICAgICBpZiAobWluX2NvdW50ID4gaS5zZWNvbmQpIHsKICAgICAgICAgICAgdHJlcyA9IGkuZmlyc3Q7CiAgICAgICAgICAgIG1pbl9jb3VudCA9IGkuc2Vjb25kOwogICAgICAgIAl9CiAgICAJfQogICAgCWlmIChtYXhfY291bnQgPT0gbWluX2NvdW50KX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