import std.stdio;
import std.ascii;
import std.algorithm;
import std.array;
import core.stdc.stdio;
int main()
{
    int t = readInt!int;
    while(t--)
    {
        string astr = readString;
        auto a = new int[](astr.length);
        auto count = new int[](4);
        foreach(i, ref ai; a)
        {
            switch(astr[i])
            {
            case 'A': ai = 0; break;
            case 'N': ai = 1; break;
            case 'T': ai = 2; break;
            case 'O': ai = 3; break;
            default: assert(0);
            }
            count[ai]++;
        }
        long minops = long.min;
        int[] minA;
        foreach(test; [[0, 1, 2, 3],[0, 1, 3, 2], [0, 2, 1, 3], [0, 2, 3, 1], [0, 3, 1, 2], [0, 3, 2, 1],
                    [1, 0, 2, 3], [1, 0, 3, 2], [1, 2, 0, 3], [1, 2, 3, 0], [1, 3, 0, 2], [1, 3, 2, 0],
                    [2, 0, 1, 3], [2, 0, 3, 1], [2, 1, 0, 3], [2, 1, 3, 0], [2, 3, 0, 1], [2, 3, 1, 0],
                    [3, 0, 1, 2], [3, 0, 2, 1], [3, 1, 0, 2], [3, 1, 2, 0], [3, 2, 0, 1], [3, 2, 1, 0]])
                    {
                        int[] testOrig;
                        foreach(ti; test)
                        {
                            foreach(i; 0 .. count[ti])
                            {
                                testOrig ~= ti;
                            }
                        }
                        long value = fixString(testOrig, a);
                        if (value > minops)
                        {
                            minops = value;
                            minA = testOrig;
                        }
                    }
        string mapi = "ANTO";
        string ans;
        foreach(ai; minA)
        {
            ans ~= mapi[ai];
        }
        writeln(ans);
    }
    return 0;
}

long fixString(int[] orig, int[] dest)
{
    int[][] pos = new int[][](4);
    auto ft = FT(cast(int)orig.length);
    foreach(i, a; dest)
    {
        pos[a] ~= cast(int) i;
    }
    long res = 0;
    foreach(i, a; orig)
    {
        int posCh = pos[a][0];
        pos[a] = pos[a][1 .. $];
        ft.add(posCh, 1);
        res += posCh - ft.sum(0, posCh - 1);
    }
    return res;
}
struct FT {
    int[] bit;
    int n;

    this(int n) {
        this.n = n;
        bit = new int[](n);
    }

    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;
    }
};



/* INPUT ROUTINES */
int currChar;
static this()
{
    currChar = getchar();
}
char topChar()
{
    return cast(char) currChar;
}
void popChar()
{
    currChar = getchar();
}
auto readInt(T)()
{
    T num = 0;
    int sgn = 0;
    while (topChar.isWhite) popChar;
    while (topChar == '-' || topChar == '+') { sgn ^= (topChar == '-'); popChar; }
    while (topChar.isDigit) { num *= 10; num += (topChar - '0'); popChar; }
    if (sgn) return -num; return num;
}
string readString()
{
    string res = "";
    while (topChar.isWhite) popChar;
    while (!topChar.isWhite) { res ~= topChar; popChar; }
    return res;
}
