#include<bits/stdc++.h>
using namespace std;
#define     int     long long
#define     MOD     1000000007
#define     po      int tc; cin>>tc; while(tc--)
#define     endl    "\n"
 
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif
 
void get_schwifty() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}

int n;

int merge(vector<int> &p, int l, int r) {
	int inv = 0;
	vector<int> temp(r-l+1);
	int m = (l+r)/2;
	int i = l;
	int j = m+1;
	int k = 0;
	while(i <= m and j <= r) {
		if(p[i] <= p[j]) {
			temp[k++] = p[i++];
		} else {
			inv += (m - i + 1);
			temp[k++] = p[j++];
		}
	}
	while(i<=m)
		temp[k++] = p[i++];
	while(j<=r)
		temp[k++] = p[j++];
	k = 0;
	for(int idx=l; idx<=r; idx++)
		p[idx] = temp[k++];
	return inv;
}
 
int merge_sort(vector<int> &p, int l, int r) {
	if(l >= r)
		return 0;
	int m = (l+r)/2;
	int inv = 0;
	inv += merge_sort(p, l, m);
	inv += merge_sort(p, m+1, r);
	inv += merge(p, l, r);
	return inv;
}
 
int count_inversions(vector<int> &p) {
	return merge_sort(p, 0, n-1);
}

void solve() {
	string s;
	cin>>s;

	n = (int)(s.size());

	unordered_map<char, int> mp;
	mp['A'] = 0;
	mp['N'] = 1;
	mp['O'] = 2;
	mp['T'] = 3;

	vector<int> cnt(4, 0);
	for(char c : s) {
		cnt[mp[c]]++;
	}

	string perm = "ANOT";

	string ans = "";
	int mx = -1;

	do {
		string temp = "";
		for(char c : perm) {
			for(int i=1; i<=cnt[mp[c]]; i++)
				temp += c;
		}

		vector<vector<int>> idx(4);
		vector<int> ptr(4, 0);
		for(int i=0; i<n; i++) {
			idx[mp[temp[i]]].push_back(i);
		}

		vector<int> p(n, -1);
		for(int i=0; i<n; i++) {
			p[i] = idx[mp[s[i]]][ptr[mp[s[i]]]++];
		}

		int inv = count_inversions(p);
		if(inv > mx) {
			ans = temp;
			mx = inv;
		}
	} while(next_permutation(perm.begin(), perm.end()));

	cout<<ans<<endl;

}

int32_t main()
{ 
    get_schwifty();
    
    po {
    	solve();
    }
    	
    return 0;
}