#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define int long long
#define endl "\n"
#define pb push_back
#define ff first
#define ss second
#define sz(w) ((int)(w).size())
#define all(w) (w).begin(), (w).end()

using ll = long long;
using pii = pair<int, int>;

const double EPS = 1e-9;
const long long INF = 1e18;

template <typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << "(" << p.first << ", " << p.second << ")"; } 
template <typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for(const T &x : v) os << sep << x, sep = ", "; return os << '}'; }

template <typename T> void debug_out(string s, T t) { cout << "[" << s << ": " << t << "]\n"; }
template <typename T, typename... U> void debug_out(string s, T t, U... u) { int w = 0, c = 0; while(w < (int)s.size()) { if(s[w] == '(') c++; if(s[w] == ')') c--; if(!c and s[w] == ',') break; w++; } cout << "[" << s.substr(0, w) << ": " << t << "] "; debug_out(s.substr(w+2, (int)s.size()-w-1), u...); } 

#define DEBUG

#ifdef DEBUG
#define dbg(Z...) debug_out(#Z, Z)
#else
#define dbg(Z...) 
#endif

const int N=1e6+5; // Change according to the question
// Reset the global variables(if any) 


struct segtree
{
    int left(int x){return 2*x+1;}
    int right(int x){return 2*x+2;}
 
    vector<int> operations; // stores operations yet to be applied
    vector<int> val; 
    int size;
 
    segtree(int n)
    {
        size=1;
        while(size<n) size*=2;
        operations.resize(2*size);
        val.resize(2*size);
    }
 
    void add(int l, int r, int v, int x, int lx, int rx)
    {
        // dbg(l, r, v, x, lx, rx);
        if(rx<=l or r<=lx)
            return;
        if(lx>=l and rx<=r)
        {
            val[x]+=v; operations[x]+=v;
            return;
        }
        int m=(lx+rx)/2;
        add(l, r, v, left(x), lx, m);
        add(l, r, v, right(x), m, rx);
        val[x]=min(val[left(x)], val[right(x)])+operations[x];
    }
    void add(int l, int r, int v){add(l, r, v, 0, 0, size);}
 
    int mini(int l, int r, int x, int lx, int rx)
    {
        if(rx<=l or r<=lx)
            return INF;
        if(lx>=l and rx<=r)
            return val[x];
        int m=(lx+rx)/2;
        int m1=mini(l, r, left(x), lx, m);
        int m2=mini(l, r, right(x), m, rx);
        return min(m1, m2)+operations[x];
    }
    int mini(int l, int r){return mini(l, r, 0, 0, size);}
};

int find_distance(vector<int> &a, vector<pii> &b, bool flg = 0)
{
    vector<int> idx2[4];
    int tempi=0;
    for(int i=0;i<sz(b);i++)
    {
        for(int j=0;j<b[i].ss;j++)
            idx2[b[i].ff].pb(tempi++);
    }
    for(int z=0;z<4;z++)
        reverse(all(idx2[z]));
    int ans=0;
    segtree st(sz(a));
    for(int i=0;i<sz(a);i++)
    {
        int val=a[i];
        int index=idx2[val].back();
        idx2[val].pop_back();
        ans+=abs(index+st.mini(index, index+1)-i);
        st.add(0, index, 1);
    }
    return ans;
}



void solve()
{
    string temp; cin>>temp;
    int n=sz(temp);
    vector<int> s;
    array<int, 4> cnt{};
    for(char c: temp)
    {
        if(c=='A') s.pb(0);
        if(c=='N') s.pb(1);
        if(c=='O') s.pb(2);
        if(c=='T') s.pb(3);
    }
    for(int x: s)
        cnt[x]++;
    vector<pii> z;
    for(int i=0;i<4;i++)
        z.pb({i, cnt[i]});
    vector<pii> ans; int mx=-1; 
    do
    {
        int value=find_distance(s, z);
        if(value>mx)
            mx=value, ans=z;
    } while(next_permutation(all(z)));
    string ANS="";
    for(int i=0;i<sz(ans);i++)
    {
        int c=ans[i].ff, times=ans[i].ss;
        if(c==0) ANS+=string(times, 'A');
        if(c==1) ANS+=string(times, 'N');
        if(c==2) ANS+=string(times, 'O');
        if(c==3) ANS+=string(times, 'T');
    }
    // find_distance(s, ans, true);
    // dbg(mx);
    cout<<ANS<<endl;
}

int32_t main()
{
    IOS;
    int T; cin >> T;
    for(int tc = 1; tc <= T; tc++)
    {
        // cout << "Case #" << tc << ": ";
        solve();
    }
    return 0;
}