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 EdA {
	static long[] mods = {1000000007, 998244353, 1000000009};
	static long mod = mods[0];
	public static MyScanner sc;
    public static PrintWriter out;
	public static void main(String[] havish) throws Exception{
		// TODO Auto-generated method stub
 		sc = new MyScanner();
 		out = new PrintWriter(System.out);
 		int t = sc.nextInt();
 		char[] arr = new char[]{'A', 'N', 'T', 'O'};
 		while(t-->0) {
 	 		char[] input = sc.next().toCharArray();
 	 		int[] counts = new int[4];
 	 		for(int j = 0;j<input.length;j++){
 	 			if (input[j] == 'A')
 	 				counts[0]++;
 	 			else if (input[j] == 'N')
 	 				counts[1]++;
 	 			else if (input[j] == 'T')
 	 				counts[2]++;
 	 			else
 	 				counts[3]++;
 	 		}
 	 		
 	 		String min = "";
 	 		long minsum = Long.MIN_VALUE;
 	 		for(int j = 0;j<4;j++){
 	 			for(int k = 0;k<4;k++){
 	 				for(int l = 0;l<4;l++){
 	 					for(int m = 0;m<4;m++){
 	 		 	 			if (j == k || j == l || j == m || k == l || k == m || l == m)
 	 		 	 				continue;
 	 		 	 			int[] curr = new int[4];
 	 		 	 			curr[j] = 0;
 	 		 	 			curr[k] = counts[j];
 	 		 	 			curr[l] = counts[j] + counts[k];
 	 		 	 			curr[m] = counts[j] + counts[k] + counts[l];
 	 		 	 			long sum = 0;
 	 		 	 			BIT bit = new BIT(input.length);
 	 		 	 			for(int s = 0;s<input.length;s++){
 	 		 	 				if (input[s] == arr[j]){
 	 		 	 					sum += (curr[j] + bit.query(curr[j],  input.length) - s);
 	 		 	 					if (curr[j] != 0)
 	 		 	 						bit.add(curr[j], 1);
 	 		 	 					curr[j] ++;
 	 		 	 				} else if (input[s] == arr[k]){
 	 		 	 				sum += (curr[k] + bit.query(curr[k],  input.length) - s);
 	 		 	 					if (curr[k] != 0)
	 		 	 					bit.add(curr[k], 1);
	 		 	 					curr[k] ++;
 	 		 	 				} else if (input[s] == arr[l]){
 	 		 	 					sum += (curr[l] + bit.query(curr[l],  input.length) - s);
	 	 		 	 				if (curr[l]!= 0)
	 		 	 					bit.add(curr[l], 1);
	 		 	 					curr[l] ++;
 	 		 	 				} else{
 	 		 	 					sum += (curr[m] + bit.query(curr[m],  input.length) - s);
	 	 		 	 				if (curr[m] != 0)
	 		 	 					bit.add(curr[m], 1);
	 		 	 					curr[m] ++;
 	 		 	 				}
 	 		 	 			}
 	 		 	 			
 	 		 	 			if (sum > minsum){
 	 		 	 				minsum = sum;
 	 		 	 				StringBuilder sb = new StringBuilder("");
 	 		 	 				for(int s = 0;s<counts[j];s++){
 	 		 	 					sb.append(arr[j]);
 	 		 	 				}
			 	 		 	 	for(int s = 0;s<counts[k];s++){
				 		 	 		sb.append(arr[k]);
				 		 	 	}
			 	 		 	 	for(int s = 0;s<counts[l];s++){
					 	 			sb.append(arr[l]);
					 	 		}
			 	 		 	 	for(int s = 0;s<counts[m];s++){
				 	 				sb.append(arr[m]);
				 	 			}
			 	 		 	 	min = sb.toString();
 	 		 	 			}
 	 		 	 		}
 	 	 	 		}
 	 	 		}
 	 		}
 	 		out.println(min);
 			
 		}
 		
 		out.close();
 		
 	}
	static class BIT {
        long[] tree;
        public BIT(int size) {
            tree = new long[size + 1];
        }
        public long sum(int i) {
            long ans = 0;
            while (i > 0) {
                ans += tree[i];
                i -= i & -i;
            }
            return ans;
        }
 
        public long query(int i, int j) {
            return sum(j) - sum(i - 1);
        }
 
        public void add(int i, long val) {
            while (i < tree.length) {
                tree[i] += val;
                i += i & -i;
            }
        }
 
        public void set(int i, long val) {
            add(i, val - query(i, i));
        }
    }
	public static void sort(int[] array){
		ArrayList<Integer> copy = new ArrayList<>();
		for (int i : array)
			copy.add(i);
		Collections.sort(copy);
		for(int i = 0;i<array.length;i++)
			array[i] = copy.get(i);
	}
	static String[] readArrayString(int n){
		String[] array = new String[n];
		for(int j =0 ;j<n;j++)
			array[j] = sc.next();
		return array;
	}
	static int[] readArrayInt(int n){
    	int[] array = new int[n];
    	for(int j = 0;j<n;j++)
    		array[j] = sc.nextInt();
    	return array;
    }
	static int[] readArrayInt1(int n){
		int[] array = new int[n+1];
		for(int j = 1;j<=n;j++){
			array[j] = sc.nextInt();
		}
		return array;
	}
	static long[] readArrayLong(int n){
		long[] array = new long[n];
		for(int j =0 ;j<n;j++)
			array[j] = sc.nextLong();
		return array;
	}
	static double[] readArrayDouble(int n){
		double[] array = new double[n];
		for(int j =0 ;j<n;j++)
			array[j] = sc.nextDouble();
		return array;
	}
	static int minIndex(int[] array){
		int minValue = Integer.MAX_VALUE;
		int minIndex = -1;
		for(int j = 0;j<array.length;j++){
			if (array[j] < minValue){
				minValue = array[j];
				minIndex = j;
			}
		}
		return minIndex;
	}
	static int minIndex(long[] array){
		long minValue = Long.MAX_VALUE;
		int minIndex = -1;
		for(int j = 0;j<array.length;j++){
			if (array[j] < minValue){
				minValue = array[j];
				minIndex = j;
			}
		}
		return minIndex;
	}
	static int minIndex(double[] array){
		double minValue = Double.MAX_VALUE;
		int minIndex = -1;
		for(int j = 0;j<array.length;j++){
			if (array[j] < minValue){
				minValue = array[j];
				minIndex = j;
			}
		}
		return minIndex;
	}
	static long power(long x, long y){
		if (y == 0)
			return 1;
		if (y%2 == 1)
			return (x*power(x, y-1))%mod;
		return power((x*x)%mod, y/2)%mod;
	}
	static void verdict(boolean a){
        out.println(a ? "YES" : "NO");
    }
    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;
        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.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 Integer.parseInt(next());
        }
        long nextLong() {
            return Long.parseLong(next());
        }
        double nextDouble() {
            return Double.parseDouble(next());
        }
        String nextLine() {
            String str = "";
            try{
                str = br.readLine();
            } 
            catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
        
    }	
}

//StringJoiner sj = new StringJoiner(" "); 
//sj.add(strings)
//sj.toString() gives string of those stuff w spaces or whatever that sequence is