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.*;
import java.util.*;
//TODO: Change length acc to max length of input string in nextLine()

public class Main {
    private static FastScanner in;
    private static PrintWriter out;
    private static final char[] letters = {'A', 'N', 'O', 'T'};

    static class Permutation {
        private int n;
        private int[] a;
        private int commonPrefix;

        Permutation (int n) {
            this.n = n;
            a = new int[this.n];
            for (int i = 0; i < this.n; ++i) {
                a[i] = i + 1;
            }
            commonPrefix = this.n - 2;
        }

        private void swap (int x, int y) {
            a[x] ^= a[y];
            a[y] ^= a[x];
            a[x] ^= a[y];
        }

        private boolean hasNextPermutation () {
            return commonPrefix >= 0;
        }

        public boolean nextPermutation () {
            if (!hasNextPermutation()) {
                return false;
            }
            int val = a[commonPrefix];
            for (int pos = n - 1; pos > commonPrefix; --pos) {
                if (a[pos] > val) {
                    swap(commonPrefix, pos);
                    break;
                }
            }
            for (int i = commonPrefix + 1, j = n - 1; i < j; ++i, --j) {
                swap(i, j);
            }
            commonPrefix = -1;
            for (int i = n - 2; i >= 0; --i) {
                if (a[i] < a[i + 1]) {
                    commonPrefix = i;
                    break;
                }
            }
            return true;
        }

        public int[] getPermutation () {
            return a;
        }
    }

    static void solve () throws IOException {
        String s = in.nextLine();
        int n = s.length();
        int[] cnt = new int[4];
        for (int i = 0; i < n; ++i) {
            char ch = s.charAt(i);
            for (int k = 0; k < 4; ++k) {
                if (ch == letters[k]) {
                    ++cnt[k];
                    break;
                }
            }
        }
        long[][] moves = new long[4][4];
        // moves[i][j] = #moves req to move all characters i in front of j
        for (int i = 0; i < 4; ++i) {
            for (int j = 0; j < 4; ++j) {
                if (j == i) { continue; }
                int sum = 0;
                for (int k = 0; k < n; ++k) {
                    char ch = s.charAt(k);
                    if (ch == letters[i]) {
                        moves[i][j] += sum;
                    } else if (ch == letters[j]) {
                        ++sum;
                    }
                }
            }
        }
        Permutation p = new Permutation(4);
        String best = s;
        long ans = 0;
        do {
            int[] a = p.getPermutation();
            StringBuffer t = new StringBuffer();
            for (int val : a) {
                for (int i = 0; i < cnt[val - 1]; ++i) {
                    t.append(letters[val - 1]);
                }
            }
            long candidate = 0;
            for (int i = 0; i + 1 < 4; ++i) {
                for (int j = i + 1; j < 4; ++j) {
                    candidate += moves[a[i] - 1][a[j] - 1];
                }
            }
            if (candidate > ans) {
                ans = candidate;
                best = new String(t);
            }
        } while (p.nextPermutation());
        out.println(best);
    }

    public static void main (String[] args) throws IOException {
        if (System.getProperty("ONLINE_JUDGE") == null) {
            in = new FastScanner(new FileInputStream("input.txt"));
            out = new PrintWriter("output.txt");
        } else {
            in = new FastScanner();
            out = new PrintWriter(System.out);
        }
        int nTest = 1;
        nTest = in.nextInt();
        for (int testcase = 1; testcase <= nTest; ++testcase) {
            solve();
        }
        out.flush();
    }

    // ----------------- SORT -------------------
    static void sort (int[] a) {
        ArrayList<Integer> arr = new ArrayList<>();
        for (int val : a) {
            arr.add(val);
        }
        Collections.sort(arr);
        for (int i = 0; i < a.length; ++i) {
            a[i] = arr.get(i);
        }
    }

    // --------------------- I/O ---------------------
    static class FastScanner {
        private static BufferedInputStream bin;
        final private int N = 1 << 13;
        private byte[] buf;
        private int ptr, siz;

        FastScanner () throws IOException {
            bin = new BufferedInputStream(System.in);
            buf = new byte[N];
            ptr = siz = 0;
        }

        FastScanner (FileInputStream in) throws IOException {
            bin = new BufferedInputStream(in);
            buf = new byte[N];
            ptr = siz = 0;
        }

        private void fill () throws IOException {
            siz = bin.read(buf, 0, N);
            if (siz == -1) {
                buf[0] = -1;
            }
        }

        private byte read () throws IOException {
            if (ptr == siz) {
                fill();
                ptr = 0;
            }
            return buf[ptr++];
        }

        private boolean isWhiteSpace (byte c) {
            return c == ' ' || c == '\n' || c == '\t' || c == '\r';
        }

        public String nextLine () throws IOException {
            final int maxLength = 1000 * 100 + 5;
            byte[] s = new byte[maxLength];
            byte c = read();
            int len = 0;
            while (isWhiteSpace(c)) {
                c = read();
            }
            for (; c != -1 && c != '\n' && c != '\r'; c = read()) {
                s[len++] = c;
            }
            return new String(s, 0, len);
        }

        public int nextInt () throws IOException {
            int res = 0;
            byte c = read();
            while (isWhiteSpace(c)) {
                c = read();
            }
            boolean neg = false;
            if (c == '-') {
                neg = true;
                c = read();
            }
            for (; c >= '0' && c <= '9'; c = read()) {
                res = res * 10 + c - '0';
            }
            return neg ? -res : res;
        }

        public long nextLong () throws IOException {
            long res = 0;
            byte c = read();
            while (isWhiteSpace(c)) {
                c = read();
            }
            boolean neg = false;
            if (c == '-') {
                neg = true;
                c = read();
            }
            for (; c >= '0' && c <= '9'; c = read()) {
                res = res * 10 + c - '0';
            }
            return neg ? -res : res;
        }

        public double nextDouble () throws IOException {
            double res = 0, div = 1;
            byte c = read();
            while (isWhiteSpace(c)) {
                c = read();
            }
            boolean neg = false;
            if (c == '-') {
                neg = true;
                c = read();
            }
            for (; c >= '0' && c <= '9'; c = read()) {
                res = res * 10 + c - '0';
            }
            if (c == '.') {
                for (c = read(); c >= '0' && c <= '9'; c = read()) {
                    res += (c - '0') / div;
                    div *= 10;
                }
            }
            return neg ? -res : res;
        }
    }
}