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.util.*;
import java.io.*;

public class Main {
    static FastScanner sc = new FastScanner(System.in);
    static PrintWriter pw = new PrintWriter(System.out);
    static StringBuilder sb = new StringBuilder();
    static long mod = (long) 1e9 + 7;

    public static void main(String[] args) throws Exception {
        int t = sc.nextInt();
        for(int i = 0; i < t; i++)solve();
        pw.flush();
    }

    public static void solve() {
        ArrayList<ArrayList<Integer>> anton = new ArrayList<>();
        for(int i = 0; i < 4; i++){
            anton.add(new ArrayList<>());
        }
        char[] s = sc.next().toCharArray();
        long max = 0;
        int[] maxArr = new int[]{0,1,2,3};
        for(int i = 0; i < s.length; i++){
            if(s[i] == 'A'){
                anton.get(0).add(i);
            }else if(s[i] == 'N'){
                anton.get(1).add(i);
            }else if(s[i] == 'T'){
                anton.get(2).add(i);
            }else{
                anton.get(3).add(i);
            }
        }
        int[] order = new int[]{0,1,2,3};
        
        do{
            int index = 1;
            long tmp = 0;
            BIT bit = new BIT(s.length+3);
            for(int i = 0; i < 4; i++){
                for(int v : anton.get(order[i])){
                    bit.add(v+1,1);
                    tmp += Math.max(0,v+1-bit.sum(v+1));
                    index++;
                }
            }
            if(tmp > max){
                System.arraycopy(order, 0, maxArr, 0, 4);
                max = tmp;
            }
        }while(nextPermutation(order));
        
        for(int i = 0; i < 4; i++){
            for(int v : anton.get(maxArr[i])){
                if(maxArr[i] == 0){
                    sb.append('A');
                }else if(maxArr[i] == 1){
                    sb.append('N');
                }else if(maxArr[i] == 2){
                    sb.append('T');
                }else{
                    sb.append('O');
                }
            }
        }
        pw.println(sb.toString());
        sb.setLength(0);
    }
    
    static boolean nextPermutation (int[] arr) {
        int pivotPos = -1;
        int pivot = 0;
        for (int i=arr.length-2; i>=0; i--) {
            if (arr[i] < arr[i+1]) {
                pivotPos = i;
                pivot = arr[i];
                break;
            }
        }
        if (pivotPos==-1) return false;
        
        int L = pivotPos, R = arr.length-1;
        int minPos = -1;
        int min = Integer.MAX_VALUE;
        for (int i=R; i>=L; i--) {
            if (pivot < arr[i]) {
                if (arr[i] < min) {
                    min = arr[i];
                    minPos = i;
                }
            }
        }
        {
            int tmp = arr[minPos];
            arr[minPos] = arr[pivotPos];
            arr[pivotPos] = tmp;
        }
        
        for (int i = 1; i < arr.length; i++) {
            if(L+i > arr.length-i) break;
            int tmp = arr[L+i];
            arr[L+i] = arr[arr.length-i];
            arr[arr.length-i] = tmp;
        }
        return true;
    }
        

    static class GeekInteger {
        public static void save_sort(int[] array) {
            shuffle(array);
            Arrays.sort(array);
        }

        public static int[] shuffle(int[] array) {
            int n = array.length;
            Random random = new Random();
            for (int i = 0, j; i < n; i++) {
                j = i + random.nextInt(n - i);
                int randomElement = array[j];
                array[j] = array[i];
                array[i] = randomElement;
            }
            return array;
        }

        public static void save_sort(long[] array) {
            shuffle(array);
            Arrays.sort(array);
        }

        public static long[] shuffle(long[] array) {
            int n = array.length;
            Random random = new Random();
            for (int i = 0, j; i < n; i++) {
                j = i + random.nextInt(n - i);
                long randomElement = array[j];
                array[j] = array[i];
                array[i] = randomElement;
            }
            return array;
        }

    }
}

class BIT {
    static int size;
    static long[] bit;

    public BIT(long[] b) {
        this.bit = b;
        this.size = b.length;
    }

    public BIT(int sz) {
        this.size = sz + 2;
        this.bit = new long[size + 2];
    }

    static void add(int pos, long x) {
        pos++;
        while (pos <= size) {
            bit[pos] += x;
            pos += (pos & -pos);
        }
    }

    static long sum(int pos) {
        long s = 0;
        pos++;
        while (pos > 0) {
            s += bit[pos];
            pos -= (pos & -pos);
        }
        return s;
    }
}

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

    public FastScanner(FileReader in) {
        reader = new BufferedReader(in);
        tokenizer = null;
    }

    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken("\n");
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }

    public String[] nextArray(int n) {
        String[] a = new String[n];
        for (int i = 0; i < n; i++)
            a[i] = next();
        return a;
    }

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    }
}