#include <bits/stdc++.h>

using namespace std;
typedef long long LL;

map<char, int> a = {{'A', 0}, {'N', 1}, {'T', 2}, {'O', 3}};
string b = "ANTO";
LL dp[4][4];
int cnt[4], perm[4], permBuna[4], vf[4];

void generare(int k, LL &sol)
{
    if(k == 4)
    {
        LL suma = 0;

        for(int i = 0; i < 4; i++)
            for(int j = i + 1; j < 4; j++)
                suma += dp[perm[j]][perm[i]];

        if(sol < suma)
        {
            sol = suma;

            for(int i = 0; i < 4; i++)
                permBuna[i] = perm[i];
        }

        return;
    }

    for(int i = 0; i < 4; i++)
        if(!vf[i])
        {
            perm[k] = i;
            vf[i] = 1;
            generare(k + 1, sol);
            vf[i] = 0;
        }
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int t;

    cin >> t;

    for(int test = 0; test < t; test++)
    {
        string s;

        cin >> s;

        memset(cnt, 0, sizeof(cnt));
        memset(dp, 0, sizeof(dp));

        for(auto c : s)
        {
            for(int i = 0; i < 4; i++)
                dp[i][a[c]] += cnt[i];

            cnt[a[c]]++;
        }

        LL sol = -1LL;
        generare(0, sol);

        for(int i = 0; i < 4; i++)
            for(int j = 0; j < cnt[permBuna[i]]; j++)
                cout << b[permBuna[i]];

        cout << '\n';
    }

    return 0;
}
