#include <bits/stdc++.h>
using namespace std;
int t, n, cur;
char a[200002], tem[200001], p[200001];
map <char, int> ds;
int main()
{
cin >> t;
while (t--)
{
ds.clear(), cur = 0;
cin >> n;
for (int i = 1; i <= n; i++)
{
cin >> a[i];
tem[i] = a[i];
}
sort(a + 1, a + n + 1);
for (int i = 1; i <= n; i++)
if (a[i] != a[i + 1])
p[++cur] = a[i];
for (int i = 1; i <= cur; i++)
ds[p[i]] = i;
for (int i = 1; i <= n; i++)
cout << p[cur - ds[tem[i]] + 1];
puts("");
}
return 0;
}