#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
int n;
map<char, int> mp;
string a;
LL check(string s){
    LL res = 0;
    for(int i = 0; i < n; i ++){
        int sum = 0;
        for(int j = 0; j < 4; j ++){
            if(s[j] == a[i]){
                res += sum;
                mp[s[j]] --;
                break;
            }
            sum += mp[s[j]];
        }
    }
    return res;
}
int main(){
    int T;
    string s;
    cin >> T;
    while(T --){
        cin >> a;
        n = a.size();
        mp.clear();
        s = "ANTO";
        sort(s.begin(), s.end());
        LL res = -1;
        string ans;
        do{
            for(int i = 0; i < n; i ++) mp[a[i]] ++;
            LL t = check(s);
            if(t > res){
                res = t;
                ans = s;
            }
        } while(next_permutation(s.begin(), s.end()));
        for(int i = 0; i < n; i ++) mp[a[i]] ++;
        for(int i = 0; i < 4; i ++){
            while(mp[ans[i]]){
                cout << ans[i];
                mp[ans[i]] --;
            }
        }
        cout << endl;
    }
    return 0;
}