#include <bits/stdc++.h>


using namespace std;
#define int long long


signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    int t;
    cin >> t;
    for (int z = 0; z < t; ++z) {
        string s;
        cin >> s;
        unordered_map <char, int> a, a1;
        for (auto i:s) {
            a[i]++;
        }
        vector<char> per = {'A', 'N', 'O', 'T'};
        int ans = 0;
        vector<char> an = per;
        for (int i = 0; i < 24; ++i) {
            a1 = a;
            int res = 0;
            for (auto j:s) {
                int k = 0;
                while (per[k] != j) res += a1[per[k]], k++;
                a1[per[k]]--;
            }
            if (ans < res) ans = res, an = per;
            next_permutation(per.begin(), per.end());
        }
        for (int i = 0; i < 4; ++i) {
            for (int j = 0; j < a[an[i]]; ++j) {
                cout << an[i];
            }
        }
        cout << '\n';
    }
}
