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.*;

public class Main{
	static class fenwickTree {
		int n;
		int[]ft;
		fenwickTree(int z){
			ft=new int[z+1];
			n=z;
			
		}
		
		void updateSum(int idx,int k) {
			while(idx<=n) {
				ft[idx]+=k;
				idx+=(idx&(-1*idx));
			}
			
		}
		long querySum(int idx) {
			long sum=0;
			while(idx>0) {
				sum+=ft[idx];
				idx-=(idx&(-1*idx));
			}
			return sum;
		}
	}
	static int[]original;
	static long ans(int[]arr) {
		long ans=0;
		LinkedList<Integer>[]pos=new LinkedList[4];
		for(int i=0;i<4;i++)pos[i]=new LinkedList<Integer>();
		for(int i=0;i<arr.length;i++)pos[arr[i]].add(i);
		
		int[]nums=new int[arr.length];
		for(int i=0;i<original.length;i++) {
			int idx=pos[original[i]].pollFirst();
			nums[idx]=i+1;
		}
		
		fenwickTree ft=new fenwickTree(arr.length+1);
		for(int i=original.length-1;i>=0;i--) {
			if(nums[i]-1>=0)
				ans+=ft.querySum(nums[i]-1);
			ft.updateSum(nums[i], 1);
		}
		return ans;
	}
	static HashMap<Character, Integer>map;
	static char[]rev= {'A','N','T','O'};
	static int[] transform(char[]in) {
		int[]ans=new int[in.length];
		for(int i=0;i<in.length;i++) {
			ans[i]=map.get(in[i]);
		}
		return ans;
	}
	static String revtransform(int[]in) {
		StringBuilder ans=new StringBuilder();
		for(int i=0;i<in.length;i++) {
			ans.append(rev[in[i]]);
		}
		return ans.toString();
	}
	static int[]cnts;
	static long res;
	static int[]cur;
	static void perms(int msk,int[]order,int idx) {
		if(idx==4) {
			int[]arr=new int[original.length];
			int o=0;
			for(int i=0;i<4;i++) {
				for(int j=0;j<cnts[order[i]];j++) {
					arr[o++]=order[i];
				}
			}
			long curans=ans(arr);
			if(curans>res) {
				res=curans;
				cur=order.clone();
			}
			return;
		}
		for(int i=0;i<4;i++) {
			if(((msk>>i)&1)==1)continue;
			int[]tmp=order.clone();
			tmp[idx]=i;
			perms(msk|(1<<i), tmp, idx+1);
		}
	}
	static void main() throws Exception{
		original=transform(sc.nextLine().toCharArray());
		cnts=new int[4];
		for(int i=0;i<original.length;i++)cnts[original[i]]++;
		res=-1;
		cur=new int[4];
		perms(0, new int[4], 0);
		int[]arr=new int[original.length];
		int o=0;
		for(int i=0;i<4;i++) {
			for(int j=0;j<cnts[cur[i]];j++) {
				arr[o++]=cur[i];
			}
		}
//		pw.println(res);
		pw.println(revtransform(arr));
	}
	public static void main(String[] args) throws Exception{
		sc=new MScanner(System.in);
		pw = new PrintWriter(System.out);
		map=new HashMap<Character, Integer>();
		map.put('A', 0);
		map.put('N', 1);
		map.put('T', 2);
		map.put('O', 3);
		
		int tc=1;
        tc=sc.nextInt();
		for(int i=1;i<=tc;i++) {
//			pw.printf("Case #%d: ", i);
			main();
		}
		
		pw.flush();
	}
	static PrintWriter pw;
	static MScanner sc;
	static class MScanner {
		StringTokenizer st;
		BufferedReader br;
		public MScanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}
	 
		public MScanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}
	 
		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
		public int[] intArr(int n) throws IOException {
	        int[]in=new int[n];for(int i=0;i<n;i++)in[i]=nextInt();
	        return in;
		}
		public long[] longArr(int n) throws IOException {
	        long[]in=new long[n];for(int i=0;i<n;i++)in[i]=nextLong();
	        return in;
		}
		public int[] intSortedArr(int n) throws IOException {
	        int[]in=new int[n];for(int i=0;i<n;i++)in[i]=nextInt();
	        shuffle(in);
	        Arrays.sort(in);
	        return in;
		}
		public long[] longSortedArr(int n) throws IOException {
	        long[]in=new long[n];for(int i=0;i<n;i++)in[i]=nextLong();
	        shuffle(in);
	        Arrays.sort(in);
	        return in;
		}
		public Integer[] IntegerArr(int n) throws IOException {
	        Integer[]in=new Integer[n];for(int i=0;i<n;i++)in[i]=nextInt();
	        return in;
		}
		public Long[] LongArr(int n) throws IOException {
	        Long[]in=new Long[n];for(int i=0;i<n;i++)in[i]=nextLong();
	        return in;
		}
		public String nextLine() throws IOException {
			return br.readLine();
		}
	 
		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}
	 
		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}
	 
		public char nextChar() throws IOException {
			return next().charAt(0);
		}
	 
		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}
	 
		public boolean ready() throws IOException {
			return br.ready();
		}
	 
		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
		
	}
	static void shuffle(int[]in) {
		for(int i=0;i<in.length;i++) {
			int idx=(int)(Math.random()*in.length);
			int tmp=in[i];
			in[i]=in[idx];
			in[idx]=tmp;
		}
	}
	static void shuffle(long[]in) {
		for(int i=0;i<in.length;i++) {
			int idx=(int)(Math.random()*in.length);
			long tmp=in[i];
			in[i]=in[idx];
			in[idx]=tmp;
		}
	}
}