Problem: After rejecting 10^{100} data structure problems, Errorgorn is very angry at Anton and decided to kill him.

Anton's DNA can be represented as a string a which only contains the characters "ANTON" (there are only 4 distinct characters). 

Errorgorn can change Anton's DNA into string b which must be a permutation of a. However, Anton's body can defend against this attack. In 1 second, his body can swap 2 adjacent characters of his DNA to transform it back to a. Anton's body is smart and will use the minimum number of moves.

To maximize the chance of Anton dying, Errorgorn wants to change Anton's DNA the string that maximizes the time for Anton's body to revert his DNA. But since Errorgorn is busy making more data structure problems, he needs your help to find the best string B. Can you help him?

Input

The first line of input contains a single integer t (1 ≤ t ≤ 100000) — the number of testcases.

The first and only line of each testcase contains 1 string a (1 ≤ |a| ≤ 100000). a consists of only the characters "A", "N", "O" and "T".

It is guaranteed that the sum of |a| over all testcases does not exceed 100000.

Output

For each testcase, print a single string, b. If there are multiple answers, you can output any one of them. b must be a permutation of the string a.

Example

Input


4
ANTON
NAAN
AAAAAA
OAANTTON


Output


NNOTA
AANN
AAAAAA
TNNTAOOA

Note

For the first testcase, it takes 7 seconds for Anton's body to transform NNOTA to ANTON: 

NNOTA → NNOAT → NNAOT → NANOT → NANTO → ANNTO → ANTNO → ANTON. 

Note that you cannot output strings such as AANTON, ANTONTRYGUB, AAAAA and anton as it is not a permutation of ANTON.

For the second testcase, it takes 2 seconds for Anton's body to transform AANN to NAAN. Note that other strings such as NNAA and ANNA will also be accepted.

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
// clang-format off
using namespace std; using ll=long long; using ull=unsigned long long; using pll=pair<ll,ll>; const ll INF=4e18;
void print0(){}; template<typename H,typename... T> void print0(H h,T... t){cout<<fixed<<setprecision(15)<<h;print0(t...);}
void print(){print0("\n");}; template<typename H,typename... T>void print(H h,T... t){print0(h);if(sizeof...(T)>0)print0(" ");print(t...);}
void perr0(){}; template<typename H,typename... T> void perr0(H h,T... t){cerr<<fixed<<setprecision(10)<<h;perr0(t...);}
void perr(){perr0("\n");}; template<typename H,typename... T>void perr(H h,T... t){perr0(h);if(sizeof...(T)>0)perr0(" ");perr(t...);}
void ioinit() { cout << fixed << setprecision(15); ios_base::sync_with_stdio(0); cin.tie(0); }
// clang-format on

template <class T>
class bsegment_tree {
   public:
    ll size;
    vector<T> data;
    T default_value;

    bsegment_tree(ll n) {
        default_value = get_default_value();

        ll siz = 1;
        while (siz < n) {
            siz = siz * 2;
        }
        data.resize(siz * 2, default_value);
        size = siz;
    }

    ~bsegment_tree() {}

    //----------------------------
    T compare(T& a, T& b) {
        return a + b;
    }
    T get_default_value() {
        return 0;
    }
    //----------------------------

    void update(ll k, T value) {
        k += size - 1;
        data[k] = value;

        while (k > 0) {
            k = (k - 1) / 2;
            data[k] = compare(data[k * 2 + 1], data[k * 2 + 2]);
        }
    }

    T query_open(ll a, ll b, ll k, ll l, ll r) {
        if (r <= a || b <= l) {
            return default_value;
        }
        if (a <= l && r <= b) {
            return data[k];
        }

        T vl = query_open(a, b, k * 2 + 1, l, (l + r) / 2);
        T vr = query_open(a, b, k * 2 + 2, (l + r) / 2, r);
        return compare(vl, vr);
    }

    T query(ll a, ll b) {
        return query_open(a, b + 1, 0, 0, size);
    }
};
using segment_tree = bsegment_tree<ll>;
ll calc(vector<ll>& s, vector<ll>& t) {
    ll n = s.size();
    vector<stack<ll>> torg(4);
    for (ll i = 0; i < n; i++) {
        torg[t[i]].push(i);
    }
    segment_tree seg(n);
    // for (ll i = 0; i < n; i++) {
    //     //seg.update(i, 1);
    // }
    ll ans = 0;
    for (ll i = n - 1; i >= 0; i--) {
        ll c = s[i];
        ll j0 = torg[c].top();
        torg[c].pop();
        ll j = j0 - seg.query(0, j0 - 1);
        seg.update(j0, 1);
        ans += abs(j - i);
        //print(i, j0, j);
    }
    return ans;
}
void solve() {
    string s0;
    cin >> s0;
    ll n = s0.size();
    vector<ll> s(n);

    // A,N,O,T
    for (ll i = 0; i < n; i++) {
        if (s0[i] == 'A') s[i] = 0;
        if (s0[i] == 'N') s[i] = 1;
        if (s0[i] == 'O') s[i] = 2;
        if (s0[i] == 'T') s[i] = 3;
    }

    ll m = 4;
    vector<ll> cnt(m);
    for (ll i = 0; i < n; i++) {
        cnt[s[i]]++;
    }

    vector<ll> indices(m);
    indices[1] = 1;
    indices[2] = 2;
    indices[3] = 3;

    ll maxnum = -1;
    ll maxperm[4];
    do {
        vector<ll> t;
        for (auto c : indices) {
            for (ll i = 0; i < cnt[c]; i++) {
                t.push_back(c);
            }
        }

        // if (!(indices[0] == 1 &&
        //       indices[1] == 2 &&
        //       indices[2] == 3 &&
        //       indices[3] == 0)) continue;

        ll ans = calc(s, t);
        if (ans > maxnum) {
            maxnum = ans;
            maxperm[0] = indices[0];
            maxperm[1] = indices[1];
            maxperm[2] = indices[2];
            maxperm[3] = indices[3];
        }
    } while (next_permutation(indices.begin(), indices.end()));
    string tt;
    for (ll d = 0; d < m; d++) {
        ll c = maxperm[d];
        char b = 'A';
        if (c == 1) b = 'N';
        if (c == 2) b = 'O';
        if (c == 3) b = 'T';
        for (ll i = 0; i < cnt[c]; i++) {
            tt.push_back(b);
        }
    }
    print(tt);
}
int main() {
    ioinit();
    ll t;
    cin >> t;
    while (t--) {
        solve();
    }
}