// Problem: D. Kill Anton
// Contest: Codeforces - Codeforces Round #723 (Div. 2)
// URL: https://codeforces.com/contest/1526/problem/D
// Memory Limit: 512 MB
// Time Limit: 2000 ms
// FishingRod

#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
typedef long long LL;
typedef pair<int,int> PII;
#define MULINPUT
/*DATA & KEY

*/
int T;
const int N=2E5+10;
int num[N],sort_tmp[N];
int get_id(char c)//获取对应id
{
	if(c=='A')return 0;
	if(c=='N')return 1;
	if(c=='T')return 2;
	if(c=='O')return 3;
}
LL merge_sort(int l,int r)//归并求逆序对
{
    if(l>=r)return 0;
    int mid=l+r>>1;
    LL res=merge_sort(l,mid)+merge_sort(mid+1,r);
    int k=0,i=l,j=mid+1;//i是l别打成1
    while(i<=mid&&j<=r)
    {
        if(num[i]<=num[j])sort_tmp[k++]=num[i++];
        else
        {
            sort_tmp[k++]=num[j++];
            res+=mid-i+1;//q[i]>q[j]，左区间剩下的所有数与右区间当前数成为逆序对
        }
    }
    while(i<=mid)sort_tmp[k++]=num[i++];     //扫尾
    while(j<=r)sort_tmp[k++]=num[j++];
    for(int i=l,j=0;i<=r;i++,j++)num[i]=sort_tmp[j];//不要写成i=1
    return res;
}
LL get_rev(string s,int* p){//求字符串逆序对数量
	int len=s.length();
	for(int i=0;i<len;i++)
		for(int j=0;j<4;j++)
			if(get_id(s[i])==p[j])//根据排序比较规则p[j]，把string映射成数组求逆序对
			{	
				num[i]=j;//下标j就是rank
				break;
			}
	return merge_sort(0,len-1);
}
void solve(int C)
{
	//NEW DATA CLEAN
	//NOTE!!!
	int p[]={0,1,2,3};//排列顺序，同时也是求逆序对数的排序比较规则
	string s;cin>>s;
	string ans,A,N,T,O;
	for(int i=0;s[i];i++)
	{
		if(s[i]=='A')A+='A';
		if(s[i]=='N')N+='N';
		if(s[i]=='T')T+='T';
		if(s[i]=='O')O+='O';
	}
	LL rev=0;
	do{
		string tmp;
		for(int i=0;i<4;i++){
			if(p[i]==0)tmp+=A;
			if(p[i]==1)tmp+=N;
			if(p[i]==2)tmp+=T;
			if(p[i]==3)tmp+=O;	
		}
		LL k=get_rev(s,p);
		if(k>=rev)
		{
			rev=k;
			ans=tmp;
		}
	}while(next_permutation(p,p+4));
	cout<<ans<<endl;
}

int main()
{
	#ifdef MULINPUT
		scanf("%d",&T);
		for(int i=1;i<=T;i++)solve(i);
	#else
		solve(1);
	#endif
	return 0;
}

