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:
//  zukonit14 - Kunal Raut

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

// #include "ext/pb_ds/assoc_container.hpp"
// #include "ext/pb_ds/tree_policy.hpp"
// using namespace __gnu_pbds;

// template<class T>
// using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update> ;

// template<class key, class value, class cmp = std::less<key>>
// using omap = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>;
// find_by_order(k)  returns iterator to kth element starting from 0;
// order_of_key(k) returns count of elements strictly smaller than k;

/*/-----------------------------DEFINES----------------------------------/*/

#define ll                  long long
#define int                 long long
#define ld                  long double
#define pb                  push_back
#define mp                  make_pair
#define fi                  first
#define se                  second
#define pi                  3.1415926535
#define all(v)              v.begin(), v.end()
#define allr(v)             v.rbegin(), v.rend()
#define ms(s, n)            memset(s, n, sizeof(s))
#define prec(n)             fixed<<setprecision(n)
#define forci(p,n)          for(ll i=p;i<(ll)n;i++)
#define forcj(p,n)          for(ll j=p;j<(ll)n;j++)
#define forc(i,p,n)            for(ll i=p;i<(ll)n;i++)
#define bolt                ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define bits(a)             __builtin_popcountll(a)
#define djokovic            freopen("input00.txt", "r", stdin);freopen("output00.txt", "w", stdout);
#define inrange(i,a,b)      ((i>=min(a,b)) && (i<=max(a,b)))
#define sz(a)               (ll)a.size()
#define sum(a)              ( accumulate ((a).begin(), (a).end(), 0ll))
#define mine(a)             (*min_element((a).begin(), (a).end()))
#define maxe(a)             (*max_element((a).begin(), (a).end()))
#define mini(a)             ( min_element((a).begin(), (a).end()) - (a).begin())
#define maxi(a)             ( max_element((a).begin(), (a).end()) - (a).begin())
#define lowb(a, x)          ( lower_bound((a).begin(), (a).end(), (x)) - (a).begin())
#define uppb(a, x)          ( upper_bound((a).begin(), (a).end(), (x)) - (a).begin())
clock_t time_p              = clock();
void rtime()                {time_p = clock() - time_p; cout << "\nTime Taken : " << fixed << (float)(time_p) / CLOCKS_PER_SEC << "s\n";}


/*/-----------------------------INLINE FUNCTIONS----------------------------------/*/

inline ll gcd(ll a, ll b)          {if (b == 0) return a;    return gcd(b, a % b);}
inline ll lcm(ll a, ll b)          {return (a / gcd(a, b) * b);}
inline bool isprime(ll n)            {ll i; for (i = 2; i <= sqrt(n); i++) {if (n % i == 0)return false;} return true;}
inline ll ceil(ll num, ll den)      {return ((num + den - 1) / den);}

/*/-----------------------------TRACE FUNCTIONS----------------------------------/*/

template<class T> ostream& operator<<(ostream &os, string V) {
    os << "[ ";
    for (auto v : V) os << v << " ";
    return os << "]";
}
template<class T> ostream& operator<<(ostream &os, vector<T> V) {
    os << "[ ";
    for (auto v : V) os << v << " ";
    return os << "]";
}
template<class T> ostream& operator<<(ostream &os, set<T> S) {
    os << "{ ";
    for (auto s : S) os << s << " ";
    return os << "}";
}
template<class T> ostream& operator<<(ostream &os, multiset<T> S) {
    os << "{ ";
    for (auto s : S) os << s << " ";
    return os << "}";
}
template<class T, class T1> ostream& operator<<(ostream &os, map<T, T1> S) {
    os << "{ ";
    for (auto s : S) os << "(" << s.first << "," << s.second << ") ";
    return os << "}";
}
template<class L, class R> ostream& operator<<(ostream &os, pair<L, R> P) {
    return os << "(" << P.first << "," << P.second << ")";
}
#define tracearr(a,n)  {cout << #a<<" : ";cout<<"[ ";for (ll i = 0; i < n; i++) cout << a[i] << " ";cout << "]\n";}
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
    cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cout.write(names, comma - names) << " : " << arg1 << " | ";
    __f(comma + 1, args...);
}
#else
#define trace(...)
#endif

/*/-----------------------------MODULAR ARITHMETIC----------------------------------/*/

const ll modx = 1e9 + 7;
// const ll modx = 998244353;
const ll mod = modx;
inline ll add(ll x, ll y, ll mod = modx) {
    x += y;
    if (x >= mod) return x - mod;
    return x % mod;
}
inline ll sub(ll x, ll y, ll mod = modx) {
    x -= y;
    if (x < 0) return x + mod;
    return x;
}
inline ll mul(ll x, ll y, ll mod = modx) {
    return (x * 1ll * y) % mod;
}
inline ll expo(ll x, ll y, ll mod = modx) {
    ll ans = 1;
    while (y) {
        if (y & 1) ans = mul(ans, x, mod);
        x = mul(x, x, mod);
        y >>= 1;
    }
    return ans % mod;
}
inline ll inv(ll x, ll mod = modx) {
    return expo(x, mod - 2, mod);
}
/*/-----------------------------CODE BEGINS----------------------------------/*/
ll rr[] = {0, 1, 1, 1, 0, -1, -1, -1};
ll cc[] = {1, 1, 0, -1, -1, -1, 0, 1};  //x-y -> URDL , row-column -> RDLU; 0-based;

const ll MAXN = 1e6 + 100, MAX2N = 2e3 + 10, LG = 31, INF = 2e18;
const ll N = MAXN;
ll n, m, k, x, q, y, z, a[MAXN];
struct BIT
{
    ll N;
    vector<ll> bit;

    void init(ll n)
    {
        N = n + 5;
        bit.assign(n + 5, 0);
    }

    void upd(ll i, ll x)
    {
        i++;
        for (; i < N; i += i & -i)
            bit[i] += x;
    }

    ll qry(ll i)
    {
        ll r = 0;
        i++;
        for (; i; i -= i & -i)
            r += bit[i];
        return r;
    }
    void show()
    {
        trace(bit);
    }
};

ll get(string s, string t)      // this will return number of adjacent swaps for converting s to t;
{
    map<char, set<ll>>mp;
    BIT b;
    b.init(n);
    for (int i = 0; i < n; i++)
    {
        mp[t[i]].insert(i);
        b.upd(i, 1);
    }
    ll ans = 0;
    for (int i = 0; i < n; i++) // now for each char encountered in S, we will take nearest same char of T and calculate no of moves;
    {
        char want = s[i];
        int index = *(mp[want].begin());
        mp[want].erase(mp[want].begin());
        ans += b.qry(index) - 1;              // beauty of BIT; ::)
        b.upd(index, -1);
    }
    return ans;
}
void solve()
{
    string s; cin >> s;
    n = sz(s);
    map<char, int>mp;
    for (auto x : s)
        mp[x]++;
    // it is observed by doing brute on permutation of s, one of the answer will have same consecutive chars; // aaabbccc, cccaaabb,bbcccaaa;
    string c = "ANOT";  // we ll use permutation of this;
    int mx = -1;
    string ans;
    do {
        string test;
        for (auto x : c)
        {
            for (int i = 0; i < mp[x]; i++)
                test += x;
        }
        int mx1 = get(s, test);
        // trace(test, mx1);
        if (mx1 > mx)
        {
            mx = mx1;
            ans = test;
        }
    } while (next_permutation(all(c)));
    cout << ans << "\n";
}
signed main()
{
    bolt;
#ifndef ONLINE_JUDGE
    djokovic;
#endif
    ll t;
    t = 1;
    cin >> t;
    for (ll i = 1; i <= t; i++)
    {
        // cout << "Case #" << i << ": ";
        solve();
    }
    //rtime();
}