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>
using namespace std;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define int long long
#define endl "\n"
#define pb push_back
#define ff first
#define ss second
#define sz(w) ((int)(w).size())
#define all(w) (w).begin(), (w).end()

using ll = long long;
using pii = pair<int, int>;

const double EPS = 1e-9;
const long long INF = 1e18;

template <typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << "(" << p.first << ", " << p.second << ")"; } 
template <typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for(const T &x : v) os << sep << x, sep = ", "; return os << '}'; }

template <typename T> void debug_out(string s, T t) { cout << "[" << s << ": " << t << "]\n"; }
template <typename T, typename... U> void debug_out(string s, T t, U... u) { int w = 0, c = 0; while(w < (int)s.size()) { if(s[w] == '(') c++; if(s[w] == ')') c--; if(!c and s[w] == ',') break; w++; } cout << "[" << s.substr(0, w) << ": " << t << "] "; debug_out(s.substr(w+2, (int)s.size()-w-1), u...); } 

#define DEBUG

#ifdef DEBUG
#define dbg(Z...) debug_out(#Z, Z)
#else
#define dbg(Z...) 
#endif

const int N=1e6+5; // Change according to the question
// Reset the global variables(if any) 


struct segtree
{
    int left(int x){return 2*x+1;}
    int right(int x){return 2*x+2;}
 
    vector<int> operations; // stores operations yet to be applied
    vector<int> val; 
    int size;
 
    segtree(int n)
    {
        size=1;
        while(size<n) size*=2;
        operations.resize(2*size);
        val.resize(2*size);
    }
 
    void add(int l, int r, int v, int x, int lx, int rx)
    {
        // dbg(l, r, v, x, lx, rx);
        if(rx<=l or r<=lx)
            return;
        if(lx>=l and rx<=r)
        {
            val[x]+=v; operations[x]+=v;
            return;
        }
        int m=(lx+rx)/2;
        add(l, r, v, left(x), lx, m);
        add(l, r, v, right(x), m, rx);
        val[x]=min(val[left(x)], val[right(x)])+operations[x];
    }
    void add(int l, int r, int v){add(l, r, v, 0, 0, size);}
 
    int mini(int l, int r, int x, int lx, int rx)
    {
        if(rx<=l or r<=lx)
            return INF;
        if(lx>=l and rx<=r)
            return val[x];
        int m=(lx+rx)/2;
        int m1=mini(l, r, left(x), lx, m);
        int m2=mini(l, r, right(x), m, rx);
        return min(m1, m2)+operations[x];
    }
    int mini(int l, int r){return mini(l, r, 0, 0, size);}
};

int find_distance(vector<int> &a, vector<pii> &b, bool flg = 0)
{
    vector<int> idx2[4];
    int tempi=0;
    for(int i=0;i<sz(b);i++)
    {
        for(int j=0;j<b[i].ss;j++)
            idx2[b[i].ff].pb(tempi++);
    }
    for(int z=0;z<4;z++)
        reverse(all(idx2[z]));
    int ans=0;
    segtree st(sz(a));
    for(int i=0;i<sz(a);i++)
    {
        int val=a[i];
        int index=idx2[val].back();
        idx2[val].pop_back();
        ans+=abs(index+st.mini(index, index+1)-i);
        st.add(0, index, 1);
    }
    return ans;
}



void solve()
{
    string temp; cin>>temp;
    int n=sz(temp);
    vector<int> s;
    array<int, 4> cnt{};
    for(char c: temp)
    {
        if(c=='A') s.pb(0);
        if(c=='N') s.pb(1);
        if(c=='O') s.pb(2);
        if(c=='T') s.pb(3);
    }
    for(int x: s)
        cnt[x]++;
    vector<pii> z;
    for(int i=0;i<4;i++)
        z.pb({i, cnt[i]});
    vector<pii> ans; int mx=-1; 
    do
    {
        int value=find_distance(s, z);
        if(value>mx)
            mx=value, ans=z;
    } while(next_permutation(all(z)));
    string ANS="";
    for(int i=0;i<sz(ans);i++)
    {
        int c=ans[i].ff, times=ans[i].ss;
        if(c==0) ANS+=string(times, 'A');
        if(c==1) ANS+=string(times, 'N');
        if(c==2) ANS+=string(times, 'O');
        if(c==3) ANS+=string(times, 'T');
    }
    // find_distance(s, ans, true);
    // dbg(mx);
    cout<<ANS<<endl;
}

int32_t main()
{
    IOS;
    int T; cin >> T;
    for(int tc = 1; tc <= T; tc++)
    {
        // cout << "Case #" << tc << ": ";
        solve();
    }
    return 0;
}