/*
 * Author    : raj1307 - Raj Singh
 * Date      : 28.05.2021
 */
 
#pragma GCC optimize("Ofast")
// #pragma GCC optimize("unroll-loops")
// #define _CRT_SECURE_NO_WARNINGS
#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;
 
#define fio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define fr(i, a, b) for(int i = (a); i < (b); ++i)
#define fb(i, b, a) for(int i = (b); i > (a); --i)
#define fill(x,y) memset(x,y,sizeof(x))
#define rr return 
#define mp make_pair
#define pb push_back
#define sz(x) ((int)x.size())
#define int long long
#define ll long long
#define ld long double
#define S second
#define F first
#define endl "\n"
#define Endl "\n"
#define all(v) (v).begin(), (v).end()
typedef pair<int, int> pii;
int max(int a,int b){if(a>b) return a; else return b;}
int min(int a,int b){if(a>b) return b; else return a;}
int gcd(int a,int b){ return (b == 0) ? a : gcd(b, a % b);}
inline int lcm(int a,int b){ return a / gcd(a, b) * b;}
inline int normalize(int x,int mod){ x %= mod; if (x < 0) x += mod; return x;}
 
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
string abc="abcdefghijklmnopqrstuvwxyz";
const double PI=acosl(-1);
const int mod = 1000*1000*1000+7;
//const int mod = 998244353; 
const int inf = 1e18+5;
 
//a and b are assumed to be taken modulo p
inline int add(int a, int b, int p = mod){ int c = a + b; if(c >= p) c -= p; return c; } // expects c doesn't exceeds 2p
inline int sub(int a, int b, int p = mod){ int c = a - b; if(c < 0) c += p; return c; } // ...  
inline int mul(int a, int b, int p = mod){ return (a * 1LL * b) % p; }  // ...

// template<typename T>
// using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>; 
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set
//To make it an ordered_multiset, use pairs of (value, time_of_insertion)
//to distinguish values which are similar.
 
int floor1(int n,int k){
    if(n%k == 0 || n >= 0)return n/k;
    return (n/k)-1;
}
 
int ceil1(int n,int k){
    return floor1(n+k-1,k);
}
 
int powm(int a, int b) {
    int res=1;
    while(b) {
        if(b&1)
            res=(res*a)%mod;
        a=(a*a)%mod;
        b>>=1;
    }
    return res;
}
 
 
const int N = 1e5 + 5;



int n;
string s;
int bit[N];
vector<int>g[26];
vector<int>p[26];

void update(int idx, int val)  // 1 - indexed
{
    while(idx<=n)
    {
        bit[idx]+=val;
        idx+=idx&-idx;
    }
}

int pref(int idx)
{
    int ans=0;
    while(idx>0)
    {
        ans+=bit[idx];
        idx-=idx&-idx;
    }
    return ans;
}

int rsum(int l, int r)
{
    return pref(r) - pref(l-1);
}


void solve(){

	cin>>s;
	n=sz(s);
	s=" "+s;
	fr(i,0,n+5) bit[i]=0;
	fr(i,0,26) g[i].clear();
	fr(i,1,n+1) g[s[i]-'A'].pb(i);


	vector<int>f;
	f.pb('A'-'A');
	f.pb('N'-'A');
	f.pb('O'-'A');
	f.pb('T'-'A');


	vector<int>ans=f;
	int mx=0;

	
	do{
		// f.clear();
		// f.pb('O'-'A');
		// f.pb('N'-'A');
		// f.pb('A'-'A');
		// f.pb('T'-'A');

		fr(i,0,26) p[i].clear();
		fr(i,0,n+5) bit[i]=0;
		string x=" ";
		int cnt=1;
		fr(i,0,4){
			fr(j,0,sz(g[f[i]])){
				x+=('A'+f[i]);
				p[f[i]].pb(cnt);
				++cnt;
			}
		}

		fr(i,1,n+1){
			p[x[i]-'A'].pb(i);
		}

		fr(i,0,26) reverse(all(p[i]));

		cnt=0;

		//cout<<x<<endl;
		
		fr(i,1,n+1){
			int nxt=p[s[i]-'A'].back();
			p[s[i]-'A'].pop_back(); // forgot
			//cout<<i<<" "<<nxt<<" "<<pref(nxt)<<" "<<abs(pref(nxt)+nxt-i)<<endl;


			cnt+=abs(pref(nxt)+nxt-i);
			// if(i<=n){
			// 	cnt+=abs(pref(nxt)+nxt-i);
			// 	update(i-pref(nxt),1);
			// 	update(nxt,-1);
			// }

			update(1,1);
			update(nxt+1,-1);
			
		}

		if(cnt>mx){
			ans=f;
			mx=cnt;

		}



	}while(next_permutation(all(f)));


	string x="";
	int cnt=1;
	fr(i,0,4){
		fr(j,0,sz(g[ans[i]])){
			x+=('A'+ans[i]);
			++cnt;
		}
	}

	cout<<x<<endl;
	
	



	

} 

 
signed main() {
    fio;
    #ifndef ONLINE_JUDGE 
        freopen("input.txt", "r", stdin); 
        freopen("output.txt", "w", stdout); 
        //freopen("error.txt", "w", stderr); 
    #endif 
    cout<<fixed<<setprecision(10);
    int t=1;
    cin>>t;  // UNCOMMENT FOR TEST-CASES
    //precompute();
    fr(i,1,t+1){
        solve();
    }   
    return 0;
}