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:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;

import static java.lang.Double.parseDouble;
import static java.lang.Integer.MIN_VALUE;
import static java.lang.Integer.parseInt;
import static java.lang.Long.parseLong;
import static java.lang.Math.max;
import static java.lang.System.*;

public class SolutionE extends Thread {
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                                            InputStreamReader(in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return parseInt(next());
        }

        long nextLong() {
            return parseLong(next());
        }

        double nextDouble() {
            return parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

    private static final FastReader scanner = new FastReader();
    private static final PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) {
        new Thread(null, new SolutionE(), "Main", 1 << 28).start();
    }

    public void run() {
        int t = scanner.nextInt();
        for (int i = 0; i < t; i++) {
            String a = scanner.next();
            solve(a);
        }


        out.close();
    }

    static final long MODULO = 998_244_353;

    private static void solve(String a) {
        int[] amount = new int[4];
        for (char c: a.toCharArray()) {
            amount[map(c)]++;
        }

        out.println(bruteforce2(a, "", amount).s);
    }

    /*
    private static long bruteforce(String a) {
        int[] amount = new int[4];
        for (char c: a.toCharArray()) {
            amount[map(c)]++;
        }


        return bruteforce(a, "", amount);
    }*/

    static class Result {
        String s;
        long score;

        public Result(String s, long score) {
            this.s = s;
            this.score = score;
        }
    }

    private static Result bruteforce2(String a, String tmp, int[] amount) {
        if (tmp.length() == a.length()) {
            long score = work(a, tmp);
            return new Result(tmp, score);
        }

        Result result = null;
        for (int i = 0; i < 4; i++) {
            if (amount[i] > 0) {
                int saved = amount[i];
                amount[i] = 0;

                StringBuilder newStr = new StringBuilder(tmp);
                for (int j = 0; j < saved; j++) {
                    newStr.append(mapBack(i));
                }

                Result tmpResult = bruteforce2(a, newStr.toString(), amount);

                if (result == null || tmpResult.score > result.score) {
                    result = tmpResult;
                }

                amount[i] = saved;
            }
        }
        return result;
    }
    
    /*
    private static long bruteforce(String a, String tmp, int[] amount) {
        if (tmp.length() == a.length()) {
            return work(a, tmp);
        }
        long result = 0;
        for (int i = 0; i < 4; i++) {
            if (amount[i] > 0) {
                amount[i]--;
                result = Math.max(result, bruteforce(a, tmp + mapBack(i), amount));
                amount[i]++;
            }
        }
        return result;
    }*/

    private static long work(String a, String b) {
        int[][] distr = new int[4][a.length()];
        int[] pointer = new int[4];
        for (int i = 0; i < a.length(); i++) {
            int number = map(a.charAt(i));
            distr[number][pointer[number]++] = i;
        }

        int[] removed = new int[a.length()];
        SimpleSegmentTree st = new SimpleSegmentTree(a.length());
        st.build(removed);

        Arrays.fill(pointer, 0);
        long score = 0;
        for (int i = 0; i < b.length(); i++) {
            int number = map(b.charAt(i));
            int indexInA = distr[number][pointer[number]];
            score += indexInA - st.calcSegment(0, indexInA);
            pointer[number]++;
            st.set(indexInA, 1);
        }
        return score;
    }


    static class SimpleSegmentTree {
        int size;
        int[] segments;

        //TODO: Change following Code to customize the Segment Tree
        //Currently its calculating the max of a segment
        /*==========*/
        int NEUTRAL_ELEMENT = 0;
        public int merge(int left, int right) {
            return left + right;
        }
        /*==========*/;

        public SimpleSegmentTree(int n) {
            size = 1;
            while (size < n) {
                size *= 2;
            }
            segments = new int[size * 2 - 1];
        }

        private void build(int[] arr, int x, int lx, int rx) {
            if (rx - lx == 1) {
                if (lx < arr.length) {
                    segments[x] = arr[lx];
                } else {
                    segments[x] = NEUTRAL_ELEMENT;
                }
            } else {
                int mid = (lx + rx) / 2;
                build(arr, x * 2 + 1, lx, mid);
                build(arr, x * 2 + 2, mid, rx);
                segments[x] = merge(segments[x * 2 + 1], segments[x * 2 + 2]);
            }
        }

        public void build(int[] arr) {
            build(arr, 0, 0, size);
        }

        private void set(int i, int v, int x, int lx, int rx) {
            if (rx - lx == 1) {
                segments[x] = v;
            } else {
                int mid = (lx + rx) / 2;
                if (i < mid) {
                    set(i, v, x * 2 + 1, lx, mid);
                } else {
                    set(i, v, x * 2 + 2, mid, rx);
                }
                segments[x] = merge(segments[x * 2 + 1], segments[x * 2 + 2]);
            }
        }

        public void set(int i, int v) {
            set(i, v, 0, 0, size);
        }

        private int calcSegment(int l, int r, int x, int lx, int rx) {
            if (l <= lx && r >= rx) {
                return segments[x];
            } else if (l >= rx || r <= lx) {
                return NEUTRAL_ELEMENT;
            } else {
                int mid = (lx + rx) / 2;
                return merge(calcSegment(l, r, x * 2 + 1, lx, mid), calcSegment(l, r, x * 2 + 2, mid, rx));
            }
        }

        public int calcSegment(int l, int r) {
            return calcSegment(l, r, 0, 0, size);
        }
    }

    private static int map(char c) {
        switch (c) {
            case 'A': return 0;
            case 'N': return 1;
            case 'O': return 2;
            case 'T': return 3;
        }
        return -1;
    }

    private static char mapBack(int i) {
        switch (i) {
            case 0: return 'A';
            case 1: return 'N';
            case 2: return 'O';
            case 3: return 'T';
        }
        return ' ';
    }
}