#include <bits/stdc++.h>
using namespace std;

char S[100005];
char T[100005];
int N;

int cnt3[256];
char W[] = {'A', 'N', 'T', 'O'};

int main(){
    int T2;
    scanf("%d", &T2);

    while(T2 --){
        scanf(" %s", S);
        N = strlen(S);

        cnt3['A'] = 0;
        cnt3['N'] = 0;
        cnt3['T'] = 0;
        cnt3['O'] = 0;
        for(int i = 0; i < N; i ++){
            cnt3[S[i]] ++;
        }

        sort(W, W+4);

        long long maxScore = -1;
        string bestStr = "";
        do{
            long long totalScore = 0;
            for(int i = 0; i < 3; i ++){
                int cnt = 0;
                for(int j = 0; j < N; j ++){
                    if(S[j] == W[i]){
                        totalScore += cnt;
                    }
                    for(int k = i+1; k < 4; k ++){
                        if(S[j] == W[k]){cnt ++;break;}
                    }
                }
            }
            if(totalScore > maxScore){
                int cnt4 = 0;
                for(int i = 0; i < 4; i ++){
                    for(int j = 0; j < cnt3[W[i]]; j ++){
                        T[cnt4 ++] = W[i];
                    }
                }
                assert(cnt4 == N);
                maxScore = totalScore;
                bestStr = string(T);
            }
        }while(next_permutation(W, W+4));

        //printf("%lld\n", maxScore);
        printf("%s\n", bestStr.c_str());

        for(int i = 0; i <= N; i ++){
            T[i] = 0;
        }
    }

    return 0;
}

