#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
string a,b,l;
int p[10];
char c[10],s[]={'A','N','O','T'};
map<char,int> mp;
int main(){
    int t,n;
    cin>>t;
    while(t--){
        ll ans=0;
        cin>>a;
        l=a;
        for(int i=1;i<=4;i++)p[i]=i;
        do{
            ll res=0;
            for(int i=1;i<=4;i++){
                c[i]=s[p[i]-1];
                mp[c[i]]=i;
                // cout<<c[i];
            }
            // cout<<endl;
            b="";
            for(int i=1;i<=4;i++){ //按全排列顺序重构字符串
                for(int j=0;j<a.size();j++){
                    if(a[j]==c[i])b+=c[i];
                }
            }
            for(int i=3;i>0;i--){
                ll tmp=0;
                for(int j=0;j<a.size();j++){
                    if(mp[a[j]]>mp[c[i]])tmp++;
                    else if(a[j]==c[i])res+=tmp;
                }
            }
            // cout<<b<<endl<<res<<endl;
            if(res>ans){
                ans=res;l=b;
            }
        }while(next_permutation(p+1,p+5));
        cout<<l<<endl;
    }
    return 0;
}