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:
//#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector")
#include <bits/stdc++.h>
#include<set>
#include <array>
using namespace std;
#define ll long long
#define endl '\n'
#define mod 1000000007
#define pb push_back
#define ff first
#define ss second
#define con continue
#define ub upper_bound
#define lb lower_bound

#define si(x) int(x.size())
#define sum_all(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())
const double pi = 2 * acos(0.0);
const int dx[] = { -1, 0, 1, 0 };
const int dy[] = { 0, -1, 0, 1 };

const int dx8[] = { -1, 0, 1, 0,1,1,-1,-1 };
const int dy8[] = { 0, -1, 0, 1,1,-1,1,-1 };

ll min(ll a,ll b)
{
    if(a<b)return a;
    return b; 
}
ll max(ll a,ll b)
{
    if(a>b)return a;
    return b; 
}
ll ceil1(ll a,ll b)
{
    return(a+b-1)/b;
}
void read(vector<ll> & arr)
{
  for(ll i=0;i<si(arr);i++)
    cin >> arr[i];

}

void read_graph(vector<vector<ll>>& g, ll m)
{
  while(m--)
  {
    ll x,y; cin >> x>> y ;
    x--,y--; 
    g[x].pb(y);
    g[y].pb(x);
  }
}


template <class T> struct fenwick_tree {
   
private:
    int _n;
    vector<T> arr;

    T query(ll x)
    {
        ll ans = 0;
        for (ll i = x; i >= 0; i = (i & (i + 1)) - 1)
        {
            ans += arr[i];
        }
        return ans;
    }
public:
    fenwick_tree() : _n(0) {}
    fenwick_tree(int n) : _n(n), arr(n) {}

    void update(ll x, T val)
    {
        ll ans = 0;

        for (ll i = x; i < arr.size(); i = (i | (i + 1)))
        {
            arr[i] += (ll)(val);
        }

    }

    T query(int l, int r) {
        return query(r) - query(l-1);
    }
   void clear()
   {
   	 for(int i=0;i<_n;i++) arr[i]=0; 
   }

};

ll calc(string &s ,string &t)
{
	
    int n=si(s);
    fenwick_tree<int> f(n);
    map<char,vector<int>> m ; 
   
      
    ll ans=0; 
	for(int i=n-1;i>=0;--i)
	{
		m[s[i]].pb(i);
	}
	vector<int> arr(n);
	for(int i=0;i<n;i++)
	{
		int ind= m[t[i]].back();
		m[t[i]].pop_back();
        arr[ind]=i; 
	}

	for(int i=n-1;i>=0;i--)
	{
		ans+=f.query(0,arr[i]);
		f.update(arr[i],1);
	}

	return ans ;
}

vector<vector<int>> Prem; 
void solve()
{

 string s,t;
 cin >> s ;
  

  	map<char,int> freq,m2;
  map<int,char>m; 
  m[0]='A',m[1]='N',m[2]='T',m[3]='O';
  m2['A']=0,m2['N']=1,m2['T']=2,m2['O']=3; 
  for(int i=0;i<si(s);i++)
  {
  	freq[s[i]]++;
  }
  
   
   string ans="";
   ll val=-10; 
     for(int i=0;i<si(Prem);++i)
     {
      vector<int> prem=Prem[i];
 	
    t="";
    for(int i1=0;i1<4;i1++)
    {
       for(int j1=0;j1<freq[m[prem[i1]]];j1++)
       t+=m[prem[i1]];
    }
    assert(si(prem)==4);
    ll val2= calc(s,t);
   
    if(val2>val)
    {
    	val=val2;
    	ans=t; 
    }
 }
  cout << ans << endl; 
}


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    Prem.clear(); 
    for(int i=0;i<4;i++) for(int j=0;j<4;j++) for(int k=0;k<4;k++) for(int l=0;l<4;l++)
 {
 	vector<int> temp({i,j,k,l});
 	sort(temp.begin(),temp.end());
     bool y=false;
 	for(int i1=0;i1<3;i1++) if(temp[i1]==temp[i1+1]) y=true;
 		if(y) continue; 
       Prem.pb({i,j,k,l});
      }
    int t; cin >> t; while (t--)
    solve();

}