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 <iostream>
//#include<stdio.h>
//using namespace std;
//chk(int x)
//{
//    if(x%100!=0&&x%4==0)return 1;
//    return 0;
//}
//int main()
//{
//    char n[11];
//    while(cin>>n)
//    {
//        int a[4];
//        for(int i=0; i<4; i++)
//            a[i]=0;
//        int tot=1;
//        for(int i=0; i<11; i++)
//        {
//            if(n[i]>='0'&&n[i]<='9')
//            {
//                a[tot]=a[tot]*10+(n[i]-48);
//            }
//            else
//            {
//                tot++;
//                if(tot>3)
//                    break;
//            }
//        }
////        cout<<a[1]<<a[2]<<a[3];
//        int ans=0;
//        for(int i=1;i<=a[2];i++)
//        {
//            if(i==a[2])
//            {
//                ans+=a[3];
//                break;
//            }
//            if(i==2&&chk(a[1]))ans+=29;
//            if(i==2&&!chk(a[1]))ans+=28;
//            if(i==1||i==3||i==5||i==7||i==8||i==10||i==12)ans+=31;
//            if(i==4||i==6||i==9||i==11)ans+=30;
//        }
//        cout<<ans<<endl;
//
//    }
//}
//#include<bits/stdc++.h>
//using namespace std;
//const int MAX=3*1e5+1;
//char s1[MAX];
//char s2[MAX];
//int p;
//int xt1[MAX];
//int xt0[MAX];
//int bt1[MAX];
//int bt0[MAX];
//int n;
//int main()
//{
//    ios::sync_with_stdio(0);
//    int t;
//    cin>>t;
//    while(t--)
//    {
//        cin>>n;
//        xt1[0]=0;
//        xt0[0]=0;
//        bt1[0]=0;
//        bt0[0]=0;
//        p=0;
//        int pl=1;
//        scanf("%s%s",s1+1,s2+1);
//        for(int i=1;i<=n;i++)
//        {
//            if(s1[i]!=s2[i])
//            {
//                p=i;
//                if(s1[i]=='1')
//                {
//                    bt1[i]=bt1[i-1]+1;
//                    bt0[i]=bt0[i-1];
//                    xt0[i]=xt0[i-1];
//                    xt1[i]=xt1[i-1];
//                }
//                else if(s1[i]=='0')
//                {
//                    bt1[i]=bt1[i-1];
//                    bt0[i]=bt0[i-1]+1;
//                    xt0[i]=xt0[i-1];
//                    xt1[i]=xt1[i-1];
//                }
//                if(s1[i-1]==s2[i-1])
//                {
//                    if(bt1[i-1]+xt1[i-1]!=bt0[i-1]+xt0[i-1])
//                    {
//                        pl=0;
//                    }
//                }
//            }
//            else
//            {
//                if(s1[i]=='1')
//                {
//                    bt1[i]=bt1[i-1];
//                    bt0[i]=bt0[i-1];
//                    xt0[i]=xt0[i-1];
//                    xt1[i]=xt1[i-1]+1;
//                }
//                else if(s1[i]=='0')
//                {
//                    bt1[i]=bt1[i-1];
//                    bt0[i]=bt0[i-1];
//                    xt0[i]=xt0[i-1]+1;
//                    xt1[i]=xt1[i-1];
//                }
//                //cout<<xt1[i]<<" "<<xt0[i]<<"s"<<i<<endl;
//                if(s1[i-1]!=s2[i-1])
//                {
//                    if(bt1[i-1]+xt1[i-1]!=bt0[i-1]+xt0[i-1])
//                    {
//                        pl=0;
//                    }
//                }
//            }
//        }
//        if(bt1[p]==bt0[p]&&xt1[p]==xt0[p]&&pl)
//        {
//            cout<<"YES"<<endl;
//        }
//        else
//        {
//            cout<<"NO"<<endl;
//        }
//    }
//}
#include<bits/stdc++.h>
using namespace std;
//const int maxn=5*1e5;
//const long long mod=499997;
//long long  num[maxn];
//long long  cnt[maxn];
//int Hash(int x)
//{
//    long long  p=x%mod;
//    while(num[p]!=0&&num[p]!=x)
//    {
//        p++;
//    }
//    return p;
//}
//long long f[100001];long long a[maxn];
//int main()
//{
//    f[0]=0;
//    for(int i=1;i<=100000;i++)
//    {
//        f[i]=f[i-1]+i;
//    }
//    int t;
//    cin>>t;
//
//    while(t--)
//    {
//        int in,n;
//        long long sum=0,sumL=0,sumR=0;
//
//        cin>>n;
//
//        for(int i=1;i<=n;i++)
//        {
//            cin>>a[i];
//            in=a[i];
//            num[Hash(in)]=in;
//            if(cnt[Hash(in)])sumR++;
//            sum+=((cnt[Hash(in)])*(n-i+1));
//           // cout<<sum<<"ep"<<endl;
//            cnt[Hash(in)]+=i;
//        }
//        for(int i=1;i<=n;i++)
//        {
//            num[Hash(a[i])]=0;
//            cnt[Hash(a[i])]=0;
//        }
//        cout<<sum<<endl;
//    }
//}
#define ll long long
const int MAX=1e5+10;
char p[5]="ANOT";
char a[MAX];
int n;
int pre[5];
int A,O,T,N;
char ck[5];
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        //cin>>n;
        scanf("%s",a+1);
        n=strlen(a+1);
        A=count(a+1,a+n+1,'A');
        O=count(a+1,a+n+1,'O');
        T=count(a+1,a+n+1,'T');
        N=count(a+1,a+n+1,'N');
        ll minn=0x3f3f3f3f3f3f;
        for(int L=1;L<=24;L++)
        {
            ll sum=0;
            memset(pre,0,sizeof pre);//cout<<n<<endl;
            for(int i=1;i<=n;i++)
            {
                for(int j=0;j<4;j++)
                {
                    if(p[j]==a[i])
                    {
                        pre[j]++;
                        break;
                    }
                    sum+=pre[j];

                }

            }
            if(sum<minn)
            {
                minn=sum;
                memcpy(ck,p,sizeof p);
            }

            next_permutation(p,p+4);
            //cout<<sum<<endl;
        }
        for(int i=0;i<4;i++)
        {
            if(ck[i]=='A')
            {
                for(int i=1;i<=A;i++)putchar('A');
            }
            else if(ck[i]=='O')
            {
                for(int i=1;i<=O;i++)putchar('O');
            }
            else if(ck[i]=='N')
            {
                for(int i=1;i<=N;i++)putchar('N');
            }
            else if(ck[i]=='T')
            {
                for(int i=1;i<=T;i++)putchar('T');
            }
        }cout<<'\n';
    }
}