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

public class Practice {
	public static long mod = (long) Math.pow(10, 9) + 7;
	public static long tt = 0;

	public static void main(String[] args) throws Exception {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter pw = new PrintWriter(System.out);
		int c = 1;
		int t = Integer.parseInt(br.readLine());

		while (t-- > 0) {
			String str = br.readLine();
			int a = 0, n = 0, o = 0, tt = 0;

			for (int i = 0; i < str.length(); i++) {
				if (str.charAt(i) == 'A') {
					a++;
				} else if (str.charAt(i) == 'N') {
					n++;
				} else if (str.charAt(i) == 'O') {
					o++;
				} else {
					tt++;
				}
			}
			long ans = -1;
			char[] gg = new char[4];
			char[] cc = new char[4];
			cc[0] = 'A';
			cc[1] = 'N';
			cc[2] = 'O';
			cc[3] = 'T';
			for (int i = 0; i < 4; i++) {
				for (int j = 0; j < 4; j++) {
					if (j == i) {
						continue;
					}
					for (int k = 0; k < 4; k++) {
						if (k == j || k == i) {
							continue;
						}
						for (int p = 0; p < 4; p++) {
							if (p == k || p == j || p == i) {
								continue;
							}
							char[] curr = new char[4];
							curr[0] = cc[i];
							curr[1] = cc[j];
							curr[2] = cc[k];
							curr[3] = cc[p];
//							for(int oo=0;oo<4;oo++) {
//								System.out.print(curr[oo]+" ");
//							}System.out.println();
							long hh = getAns(curr, a, n, o, tt, str, ans);
							if (ans < hh) {
								gg[0] = cc[i];
								gg[1] = cc[j];
								gg[2] = cc[k];
								gg[3] = cc[p];
								ans = hh;
							}
						}

					}
				}
			}
			// System.out.println(a + " " + n + " " + o + " " + t);
//			for(int i=0;i<4;i++) {
//				System.out.print(gg[i]+" ");
//			}System.out.println();
			StringBuilder ttt = new StringBuilder();
			if (gg[0] == 'A') {
				for (int i = 0; i < a; i++) {
					ttt.append('A');
				}
			} else if (gg[0] == 'N') {
				for (int i = 0; i < n; i++) {
					ttt.append('N');
				}
			} else if (gg[0] == 'O') {
				for (int i = 0; i < o; i++) {
					ttt.append('O');
				}
			} else {
				for (int i = 0; i < tt; i++) {
					ttt.append('T');
				}
			}
			gg[0] = gg[1];
			if (gg[0] == 'A') {
				for (int i = 0; i < a; i++) {
					ttt.append('A');
				}
			} else if (gg[0] == 'N') {
				for (int i = 0; i < n; i++) {
					ttt.append('N');
				}
			} else if (gg[0] == 'O') {
				for (int i = 0; i < o; i++) {
					ttt.append('O');
				}
			} else {
				for (int i = 0; i < tt; i++) {
					ttt.append('T');
				}
			}
			gg[0] = gg[2];
			if (gg[0] == 'A') {
				for (int i = 0; i < a; i++) {
					ttt.append('A');
				}
			} else if (gg[0] == 'N') {
				for (int i = 0; i < n; i++) {
					ttt.append('N');
				}
			} else if (gg[0] == 'O') {
				for (int i = 0; i < o; i++) {
					ttt.append('O');
				}
			} else {
				for (int i = 0; i < tt; i++) {
					ttt.append('T');
				}
			}
			gg[0] = gg[3];
			if (gg[0] == 'A') {
				for (int i = 0; i < a; i++) {
					ttt.append('A');
				}
			} else if (gg[0] == 'N') {
				for (int i = 0; i < n; i++) {
					ttt.append('N');
				}
			} else if (gg[0] == 'O') {
				for (int i = 0; i < o; i++) {
					ttt.append('O');
				}
			} else {
				for (int i = 0; i < tt; i++) {
					ttt.append('T');
				}
			}
			System.out.println(ttt.toString());

		}
		pw.close();
	}

	private static long getAns(char[] curr, int a, int n, int o, int t, String str, long ans2) {
		// TODO Auto-generated method stub

		HashMap<Character, Integer> map = new HashMap<>();
		int pre = 0;
		if (curr[0] == 'A') {
			map.put('A', 0);
			pre = a;

		} else if (curr[0] == 'N') {
			map.put('N', 0);
			pre = n;

		} else if (curr[0] == 'O') {
			map.put('O', 0);
			pre = o;

		} else {
			map.put('T', 0);
			pre = t;

		}
		if (curr[1] == 'A') {
			map.put('A', pre);
			pre += a;

		} else if (curr[1] == 'N') {
			map.put('N', pre);
			pre += n;

		} else if (curr[1] == 'O') {
			map.put('O', pre);
			pre += o;

		} else {
			map.put('T', pre);
			pre += t;

		}

		if (curr[2] == 'A') {
			map.put('A', pre);
			pre += a;

		} else if (curr[2] == 'N') {
			map.put('N', pre);
			pre += n;

		} else if (curr[2] == 'O') {
			map.put('O', pre);
			pre += o;

		} else {
			map.put('T', pre);
			pre += t;

		}
		if (curr[3] == 'A') {
			map.put('A', pre);
			pre += a;

		} else if (curr[3] == 'N') {
			map.put('N', pre);
			pre += n;

		} else if (curr[3] == 'O') {
			map.put('O', pre);
			pre += o;

		} else {
			map.put('T', pre);
			pre += t;

		}
		// System.out.println(map);
		long ans = 0;
		for (int i = 0; i < str.length(); i++) {
			if (str.charAt(i) == 'A') {
				ans = ans + map.get('A') - i;
				map.put('A', map.get('A') + 1);
			} else if (str.charAt(i) == 'N') {
				ans = ans + map.get('N') - i;
				map.put('N', map.get('N') + 1);
			} else if (str.charAt(i) == 'O') {
				ans = ans + map.get('O') - i;
				map.put('O', map.get('O') + 1);
			} else {
				ans = ans + map.get('T') - i;
				map.put('T', map.get('T') + 1);
			}
			if (str.charAt(i) == 'A') {
				if (curr[1] == 'A') {
					for (int l = 0; l < 1; l++) {
						map.put(curr[l], map.get(curr[l]) + 1);
					}
				} else if (curr[2] == 'A') {
					for (int l = 0; l < 2; l++) {
						map.put(curr[l], map.get(curr[l]) + 1);
					}
				} else if (curr[3] == 'A') {
					for (int l = 0; l < 3; l++) {
						map.put(curr[l], map.get(curr[l]) + 1);
					}
				}
			} else if (str.charAt(i) == 'N') {
				if (curr[1] == 'N') {
					for (int l = 0; l < 1; l++) {
						map.put(curr[l], map.get(curr[l]) + 1);
					}
				} else if (curr[2] == 'N') {
					for (int l = 0; l < 2; l++) {
						map.put(curr[l], map.get(curr[l]) + 1);
					}
				} else if (curr[3] == 'N') {
					for (int l = 0; l < 3; l++) {
						map.put(curr[l], map.get(curr[l]) + 1);
					}
				}
			} else if (str.charAt(i) == 'O') {
				if (curr[1] == 'O') {
					for (int l = 0; l < 1; l++) {
						map.put(curr[l], map.get(curr[l]) + 1);
					}
				} else if (curr[2] == 'O') {
					for (int l = 0; l < 2; l++) {
						map.put(curr[l], map.get(curr[l]) + 1);
					}
				} else if (curr[3] == 'O') {
					for (int l = 0; l < 3; l++) {
						map.put(curr[l], map.get(curr[l]) + 1);
					}
				}
			} else {
				if (curr[1] == 'T') {
					for (int l = 0; l < 1; l++) {
						map.put(curr[l], map.get(curr[l]) + 1);
					}
				} else if (curr[2] == 'T') {
					for (int l = 0; l < 2; l++) {
						map.put(curr[l], map.get(curr[l]) + 1);
					}
				} else if (curr[3] == 'T') {
					for (int l = 0; l < 3; l++) {
						map.put(curr[l], map.get(curr[l]) + 1);
					}
				}
			}
		}
		return ans;
	}

//	private static long getGCD(long l, long m) {
//		// TODO Auto-generated method stub
//
//		long t1 = Math.min(l, m);
//		long t2 = Math.max(l, m);
//		while (true) {
//			long temp = t2 % t1;
//			if (temp == 0) {
//				return t1;
//			}
//			t2 = t1;
//			t1 = temp;
//		}
//	}
}