#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(20);
    int T;
    cin >> T;
    map<char, int> M{{'A', 0}, {'N', 1}, {'T', 2}, {'O', 3}};
    string t = "ANTO";
    while (T--) {
        string s;
        cin >> s;
        int n = s.size();
        vector<int> cnt(4);
        for (int i = 0; i < n; i++) cnt[M[s[i]]]++;
        vector<vector<ll>> flips(4, vector<ll> (4));
        for (int i = 0; i < 4; i++) {
            int tot = 0;
            for (auto j : s) {
                flips[i][M[j]] += tot;
                tot += M[j] == i;
            }
        }
        ll best = -1;
        vector<int> ans;
        vector<int> v{0, 1, 2, 3};
        do {
            ll now = 0;
            for (int i = 0; i < 4; i++) {
                for (int j = i + 1; j < 4; j++) {
                    now += flips[v[j]][v[i]];
                }
            }
            if (now > best) {
                best = now;
                ans = v;
            }
        } while (next_permutation(v.begin(), v.end()));
        for (auto i : ans) {
            for (int j = 0; j < cnt[i]; j++) {
                cout << t[i];
            }
        }
        cout << '\n';
    }
    return 0;
}