#include <iostream>
#include <algorithm>
#include <utility>
#include <cstring>
#include <vector>
#include <stack>
#include <queue>
#include <map>
using namespace std;
#define ll long long
const int N = 1e5+5;
char s[N];
int a[N];
int t[N];

long long ans;
void mergesort(int l, int mid, int r)
{
    int i, j, k;
    k = 0;
    i = l;
    j = mid + 1;
    while(i <= mid && j <= r)//谁小t[]数组就存谁，直到左边或者右边数组存完
    {
        if(a[i] <= a[j])
        {
            t[k++] = a[i++];
        }
        else
        {
            t[k++] = a[j++];
            ans = ans + mid - i + 1;//t[k]>a[j] 说明t[k]后面的数都大于a[j] 所以 逆序对要加上 mid - i + 1;
        }
    }
    while(i <= mid)//把剩下的直接存进去
    {
        t[k++] = a[i++];
    }
    while(j <= r)//把剩下的直接存进去
    {
        t[k++] = a[j++];
    }
    for(i = 0; i < k; i++)//更新原来数组的值
        a[l + i] = t[i];
}
void separatesort(int l, int r)//拆分区间
{
    int mid = (l + r) / 2;
    if(l >= r) return ;
    else
    {
        separatesort(l, mid);//左边拆分
        separatesort(mid + 1, r);//右边拆分
        mergesort(l, mid, r);//递归回来归并
    }
}

int main() {
    int T;
    cin >> T;
    while(T--) {
        scanf("%s", s);
        int len = strlen(s);

        int num[4]={1,2,3,4};
        ll real_ans = -1;
        map<char, int> real_map;
        do
        {
            map<char, int> map;
            map['A'] = num[0];
            map['N'] = num[1];
            map['O'] = num[2];
            map['T'] = num[3];
            ans = 0;

            for(int i = 0; i < len; i++) {
                a[i] = map[s[i]];
            }
            separatesort(0, len-1);

            if(real_ans < ans) {
                real_ans = ans;
                real_map = map;
            }
        } while(next_permutation(num,num+4));

        int str_a, str_n, str_o, str_t;
        str_a = str_n = str_o = str_t = 0;
        for(int i = 0; i < len; i++) {
            if(s[i] == 'A') str_a++;
            if(s[i] == 'N') str_n++;
            if(s[i] == 'O') str_o++;
            if(s[i] == 'T') str_t++;
        }
        // cout << str_a + str_n + str_o + str_t << '\n';
        for(int i = 1; i <= 4; i++) {
            if(real_map['A'] == i) {
                for(int j = 0; j < str_a; j++) {
                    cout << 'A';
                }
            }
            if(real_map['N'] == i) {
                for(int j = 0; j < str_n; j++) {
                    cout << 'N';
                }
            }
            if(real_map['O'] == i) {
                for(int j = 0; j < str_o; j++) {
                    cout << 'O';
                }

            }
            if(real_map['T'] == i) {
                for(int j = 0; j < str_t; j++) {
                    cout << 'T';
                }
            }
        }
        cout << '\n';
    }
    return 0;
}