#include<bits/stdc++.h>
using namespace std;
#define ll int
#define FAST1 ios_base::sync_with_stdio(false);
#define FAST2 cin.tie(NULL);
long long getSum(long long BITree[], long long index)
{
    long long sum = 0; // Initialize result

    // Traverse ancestors of BITree[index]
    while (index > 0)
    {
        // Add current element of BITree to sum
        sum += BITree[index];

        // Move index to parent node in getSum View
        index -= index & (-index);
    }
    return sum;
}

// Updates a node in Binary Index Tree (BITree) at given index
// in BITree.  The given value 'val' is added to BITree[i] and
// all of its ancestors in tree.
void updateBIT(long long BITree[], long long n, long long index, long long val)
{
    // Traverse all ancestors and add 'val'
    while (index <= n)
    {
       // Add 'val' to current node of BI Tree
       BITree[index] += val;

       // Update index to that of parent in update View
       index += index & (-index);
    }
}

// Returns inversion count arr[0..n-1]
long long getInvCount(int arr[], long long n)
{
    long long invcount = 0; // Initialize result

    // Find maximum element in arr[]
    for (long long i=0; i<n; i++){
        arr[i]++;
    }
    long long maxElement = 0;
    for (long long i=0; i<n; i++)
        if (maxElement < arr[i])
            maxElement = arr[i];

    // Create a BIT with size equal to maxElement+1 (Extra
    // one is used so that elements can be directly be
    // used as index)
    long long BIT[maxElement+1];
    for (long long i=1; i<=maxElement; i++)
        BIT[i] = 0;

    // Traverse all elements from right.
    for (long long i=n-1; i>=0; i--)
    {
        // Get count of elements smaller than arr[i]
        invcount += getSum(BIT, arr[i]-1);

        // Add current element to BIT
        updateBIT(BIT, maxElement, arr[i], 1);
    }
     for (long long i=0; i<n; i++){
        arr[i]--;
    }
    return invcount;
}
void solve(){
    string st;
    cin>>st;
    ll n=st.size();
    unordered_map<char,ll> m;
    m['A']=0;
    m['N']=1;
    m['O']=2;
    m['T']=3;
    unordered_map<ll,char> m1;
    m1[0]='A';
    m1[1]='N';
    m1[2]='O';
    m1[3]='T';
    vector<ll> arr(n);
    for(ll i=0;i<n;i++){
        arr[i]=m[st[i]];
    }
    vector<vector<ll>> arr1(4);
    for(ll i=0;i<n;i++){
        arr1[arr[i]].push_back(i);
    }
    vector<ll> perms{0,1,2,3};
    long long best=0;
    vector<ll> given_perm=perms;
    do{
        ll cntr=0;
        ll perm[n];
        for(auto i:perms){
            for(ll j=0;j<int(arr1[i].size());j++){
                ll idx=arr1[i][j];
                perm[idx]=cntr++;
            }
        }
        long long x=getInvCount(perm,n);
        if(best<x){
            best=x;
            given_perm=perms;
        }
    }while(next_permutation(perms.begin(),perms.end()));
    ll perm[n];
    ll cntr=0;
    for(auto i:given_perm){
        for(ll j=0;j<int(arr1[i].size());j++){
            ll idx=arr1[i][j];
            perm[idx]=cntr++;
        }
    }
    string st2=st;
    for(ll i=0;i<n;i++){
        st2[perm[i]]=st[i];
    }
    cout<<st2<<endl;
}

int main(){
    FAST1;
    FAST2;
    ll t;
    cin>>t;
    while(t--){
        solve();
    }
}