/** これを翻訳している間、あなたはあなたの人生のいくつかの貴重な瞬間を無駄にしました **/
#include<bits/stdc++.h>
using namespace std;

#ifdef Zoro
  #include "headers/debug.h"
#else
  #define debug(x...)
  #define deb(x...)
#endif

#define rep(i,x,y) for(int i=x;i<y;i++)
#define repr(i,x,y) for(int i=x;i>=y;i--)
#define int long long
#define pb push_back
#define ff first
#define ss second
#define sz(x) ((int)x.size())
#define all(x) begin(x), end(x)
#define memo(x,y) memset((x),(y),sizeof((x)))
#define line cout<<"[At "<<__LINE__<<"]"<<endl;

using pii = pair<int, int>;
using vi = vector<int>;
using vii = vector<pair<int, int>>;

constexpr int mod = 1e9 + 7, N = 2e5 + 5;
constexpr long long inf = 1e18;
constexpr long double eps = 1e-6;

struct FenwickTree {
  vector<int> bit;  // binary indexed tree
  int n;

  FenwickTree(int _n) {
    this->n = _n;
    bit.assign(n+5, 0);
  }

  int sum(int r) {
    int ret = 0;
    for (; r >= 0; r = (r & (r + 1)) - 1)
      ret += bit[r];
    return ret;
  }

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

  void add(int idx, int delta) {
    for (; idx < n; idx = idx | (idx + 1))
      bit[idx] += delta;
  }
  void radd(int i,int j,int delta){
    add(i,delta);
    add(j+1,-delta);
  }
};


int countSteps(vi &v, vi &v2, int n) {
  FenwickTree f(n);
  vi nxt[4];
  for(int i = n - 1; i >= 0; i--) {
    nxt[v2[i]].pb(i);
  }

  int ans = 0;
  int i = 0, j = 0;
  string cc = "ANTO";
  while(i<n) {
    int jj = j+f.sum(j);
    int pos = nxt[v[i]].back();
    nxt[v[i]].pop_back();
    int pos2 = pos+f.sum(pos);
    ans+=pos2-jj;
    if(pos2==jj)j++;
    f.radd(0,pos,1); 
    i++;
  }
  return ans;
}
void Onigiri() {
  string w;
  cin >> w;

  map<char, int> a;
  vi v;
  for(auto &x : w) {
    if(x == 'A')v.pb(0);
    if(x == 'N')v.pb(1);
    if(x == 'T')v.pb(2);
    if(x == 'O')v.pb(3);
    a[x]++;
  }
  vii v2;
  // deb(v);
  for(auto &x : a) {
    v2.pb({x.ff, x.ss});
  }
  sort(all(v2));
  string ans = "";
  int mx = 0;
  do {
    vi v3;
    for(auto [x, y] : v2) {
      while(y--) {
        if(x == 'A')v3.pb(0);
        if(x == 'N')v3.pb(1);
        if(x == 'T')v3.pb(2);
        if(x == 'O')v3.pb(3);
      }
    }

    int temp = countSteps(v, v3, sz(v));
    if(temp >= mx) {
      ans="";
      for(auto &x : v3) {
        if(x == 0)ans += 'A';
        if(x == 1)ans += 'N';
        if(x == 2)ans += 'T';
        if(x == 3)ans += 'O';
      }
      mx=temp;
    }
  } while(next_permutation(all(v2)));

  deb(mx);
  cout << ans;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  //cout.precision(10);cout<<fixed;
#ifdef Zoro
  freopen("/home/pritish/Competitive/io/in", "r", stdin);
  freopen("/home/pritish/Competitive/io/out", "w", stdout);
#endif

  int t = 1;
  cin >> t;

  while(t--) {
    Onigiri();
    cout << "\n";
  }

  cerr << "\n" << (float)clock() / CLOCKS_PER_SEC * 1000 << " ms" << endl;
  return 0;
}