Problem: After rejecting 10^{100} data structure problems, Errorgorn is very angry at Anton and decided to kill him.

Anton's DNA can be represented as a string a which only contains the characters "ANTON" (there are only 4 distinct characters). 

Errorgorn can change Anton's DNA into string b which must be a permutation of a. However, Anton's body can defend against this attack. In 1 second, his body can swap 2 adjacent characters of his DNA to transform it back to a. Anton's body is smart and will use the minimum number of moves.

To maximize the chance of Anton dying, Errorgorn wants to change Anton's DNA the string that maximizes the time for Anton's body to revert his DNA. But since Errorgorn is busy making more data structure problems, he needs your help to find the best string B. Can you help him?

Input

The first line of input contains a single integer t (1 ≤ t ≤ 100000) — the number of testcases.

The first and only line of each testcase contains 1 string a (1 ≤ |a| ≤ 100000). a consists of only the characters "A", "N", "O" and "T".

It is guaranteed that the sum of |a| over all testcases does not exceed 100000.

Output

For each testcase, print a single string, b. If there are multiple answers, you can output any one of them. b must be a permutation of the string a.

Example

Input


4
ANTON
NAAN
AAAAAA
OAANTTON


Output


NNOTA
AANN
AAAAAA
TNNTAOOA

Note

For the first testcase, it takes 7 seconds for Anton's body to transform NNOTA to ANTON: 

NNOTA → NNOAT → NNAOT → NANOT → NANTO → ANNTO → ANTNO → ANTON. 

Note that you cannot output strings such as AANTON, ANTONTRYGUB, AAAAA and anton as it is not a permutation of ANTON.

For the second testcase, it takes 2 seconds for Anton's body to transform AANN to NAAN. Note that other strings such as NNAA and ANNA will also be accepted.

Solution (in JAVA):

Solution:
/*
stream Butter!
eggyHide eggyVengeance
I need U
xiao rerun when
 */
import static java.lang.Math.max;
import static java.lang.Math.min;
import static java.lang.Math.abs;
import static java.lang.System.out;
import java.util.*;
import java.io.*;
import java.math.*;

public class x1526D
{
    public static void main(String hi[]) throws Exception
    {
        //generate permutations
        ArrayList<int[]> perms = new ArrayList<int[]>();
        boolean[] seen = new boolean[4];
        int[] state = new int[4];
        Arrays.fill(state, -1);
        dfs(perms, seen, state, 0);
        int[] toNum = new int[420];
        toNum['A'] = 0; toNum['N'] = 1;
        toNum['T'] = 2; toNum['O'] = 3;
        int[] toChar = new int[4];
        toChar[0] = 'A'; toChar[1] = 'N';
        toChar[2] = 'T'; toChar[3] = 'O';
        FastScanner infile = new FastScanner();
        int T = infile.nextInt();
        StringBuilder sb = new StringBuilder();
        while(T-->0)
        {
            String input = infile.next();
            char[] arrInput = input.toCharArray();
            int N = arrInput.length;
            int[] arr = new int[N];
            for(int i=0; i < N; i++)
                arr[i] = toNum[arrInput[i]];
            int[] freq = new int[4];
            for(int x: arr)
                freq[x]++;
            int[] res = new int[N];
            long best = 0L;
            ArrayList<Integer>[] ordered = new ArrayList[4];
            for(int i=0; i < 4; i++)
                ordered[i] = new ArrayList<Integer>();
            for(int i=0; i < N; i++)
                ordered[arr[i]].add(i);
            for(int[] p: perms)
            {
                int[] curr = new int[N];
                int boofcurr = 0;
                for(int i=0; i < N; i++)
                {
                    while(freq[p[boofcurr]] == 0)
                        boofcurr++;
                    curr[i] = p[boofcurr];
                    freq[curr[i]]--;
                }
                //find inversions
                long inversions = 0L;
                FenwickTree bit = new FenwickTree(N+2);
                int[] dexes = new int[4];
                for(int i=0; i < N; i++)
                {
                    int val = ordered[curr[i]].get(dexes[curr[i]]++);
                    inversions += bit.find(val+1, N-1);
                    bit.add(val, 1);
                    freq[arr[i]]++;
                }
                if(best <= inversions)
                {
                    best = inversions;
                    res = curr;
                }
            }
            //System.out.println(best);
            for(int x: res)
                sb.append((char)toChar[x]);
            sb.append("\n");
        }
        System.out.print(sb);
    }
    public static void dfs(ArrayList<int[]> perms, boolean[] seen, int[] state, int val)
    {
        boolean has = false;
        for(int i=0; i < 4; i++)
            if(!seen[i])
            {
                has = true;
                seen[i] = true;
                state[i] = val;
                dfs(perms, seen, state, val+1);
                seen[i] = false;
                state[i] = -1;
            }
        if(!has)
            perms.add(state.clone());
    }
}
/*
we never swap the same characters (relative order stays the same)
equal characters must stay together

1
ANTON

 */
class FenwickTree
{
    //1 indexed
    public int[] tree;
    public int size;

    public FenwickTree(int size)
    {
        this.size = size;
        tree = new int[size+5];
    }
    public void add(int i, int v)
    {
        i++;
        while(i <= size)
        {
            tree[i] += v;
            i += i&-i;
        }
    }
    public int find(int i)
    {
        int res = 0;
        while(i >= 1)
        {
            res += tree[i];
            i -= i&-i;
        }
        return res;
    }
    public int find(int l, int r)
    {
        l++;    r++;
        return find(r)-find(l-1);
    }
}
class FastScanner
{
    private int BS = 1 << 16;
    private char NC = (char) 0;
    private byte[] buf = new byte[BS];
    private int bId = 0, size = 0;
    private char c = NC;
    private double cnt = 1;
    private BufferedInputStream in;

    public FastScanner() {
        in = new BufferedInputStream(System.in, BS);
    }

    public FastScanner(String s) {
        try {
            in = new BufferedInputStream(new FileInputStream(new File(s)), BS);
        } catch (Exception e) {
            in = new BufferedInputStream(System.in, BS);
        }
    }

    private char getChar() {
        while (bId == size) {
            try {
                size = in.read(buf);
            } catch (Exception e) {
                return NC;
            }
            if (size == -1) return NC;
            bId = 0;
        }
        return (char) buf[bId++];
    }

    public int nextInt() {
        return (int) nextLong();
    }

    public int[] nextInts(int N) {
        int[] res = new int[N];
        for (int i = 0; i < N; i++) {
            res[i] = (int) nextLong();
        }
        return res;
    }

    public long[] nextLongs(int N) {
        long[] res = new long[N];
        for (int i = 0; i < N; i++) {
            res[i] = nextLong();
        }
        return res;
    }

    public long nextLong() {
        cnt = 1;
        boolean neg = false;
        if (c == NC) c = getChar();
        for (; (c < '0' || c > '9'); c = getChar()) {
            if (c == '-') neg = true;
        }
        long res = 0;
        for (; c >= '0' && c <= '9'; c = getChar()) {
            res = (res << 3) + (res << 1) + c - '0';
            cnt *= 10;
        }
        return neg ? -res : res;
    }

    public double nextDouble() {
        double cur = nextLong();
        return c != '.' ? cur : cur + nextLong() / cnt;
    }

    public double[] nextDoubles(int N) {
        double[] res = new double[N];
        for (int i = 0; i < N; i++) {
            res[i] = nextDouble();
        }
        return res;
    }

    public String next() {
        StringBuilder res = new StringBuilder();
        while (c <= 32) c = getChar();
        while (c > 32) {
            res.append(c);
            c = getChar();
        }
        return res.toString();
    }

    public String nextLine() {
        StringBuilder res = new StringBuilder();
        while (c <= 32) c = getChar();
        while (c != '\n') {
            res.append(c);
            c = getChar();
        }
        return res.toString();
    }

    public boolean hasNext() {
        if (c > 32) return true;
        while (true) {
            c = getChar();
            if (c == NC) return false;
            else if (c > 32) return true;
        }
    }
}