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.math.BigInteger;
import java.util.ArrayList;
import java.util.Collections;
import java.util.StringTokenizer;
import java.util.*;

public class D {

  /**
   * General Idea: We want to find an permutation which has the maximum the inversion count.
   * <p>
   * Terminology: 1. Adjacent swap moves: inversions. <p> 2. Maximum steps to fix the DNA: Number of
   * inversions in the string. <p>
   */

  public static int N;
  public static int[] ft, orig;

  public static void main(String[] args) {
    // Write code here
    FastScanner fs = new FastScanner();
    int t = fs.nextInt();
    while (t-- > 0) {
      String input = fs.next();
      int n = input.length();
      int[] freq = new int[5];

      int[] inputArr = convertToArray(input);
      for (int i = 0; i < n; i++) {
        freq[inputArr[i]]++;
      }
      int[] current = {1, 2, 3, 4};
      long curr_sum = -1, max_sum = -1;
      int[] ans = inputArr;
      Initialize(n);
      while (true) {
        reset();
        int cnt = 0;
        int[] array = new int[n];
        for (int i = 0; i < current.length; i++) {
          for (int j = 0; j < freq[current[i]]; j++) {
            array[cnt++] = current[i];
          }
        }

        // Get inverted array
        int[] temp = getInverted(array, inputArr);

        curr_sum = calcInversion(temp);
        if (curr_sum > max_sum) {
          max_sum = curr_sum;
          ans = array;
        }
        nextPermutation(current);
        if (isSorted(current)) {
          break;
        }
      }
      
      System.out.println(convertToString(ans));
    }
  }

  // a->b
  public static int[] getInverted(int[] a, int[] b) {
    HashMap<Integer, Queue<Integer>> order = new HashMap<>();
    for (int i = 0; i < b.length; i++) {
      Queue<Integer> c = order.getOrDefault(b[i], new LinkedList<Integer>());
      c.add(i + 1);
      order.put(b[i], c);
    }

    int[] ans = new int[a.length];
    for (int i = 0; i < a.length; i++) {
      ans[i] = order.get(a[i]).poll();
    }

    return ans;
  }

  public static boolean isSorted(int[] a) {
    for (int i = 0; i < a.length - 1; i++) {
      if (a[i] > a[i + 1]) {
        return false;
      }
    }
    return true;
  }

  public static String convertToString(int[] array) {
    HashMap<Integer, Character> charMap = new HashMap<>();
    charMap.put(1, 'A');
    charMap.put(2, 'N');
    charMap.put(3, 'T');
    charMap.put(4, 'O');
    String ret = new String("");
    for (int i = 0; i < array.length; i++) {
      ret += charMap.get(array[i]);
    }

    return ret;
  }

  public static int[] convertToArray(String input) {
    HashMap<Character, Integer> charMap = new HashMap<>();
    charMap.put('A', 1);
    charMap.put('N', 2);
    charMap.put('T', 3);
    charMap.put('O', 4);
    int[] ans = new int[input.length()];
    for (int i = 0; i < input.length(); i++) {
      ans[i] = charMap.get(input.charAt(i));
    }

    return ans;
  }

  public static void nextPermutation(int[] nums) {
    //find first decreasing digit
    int mark = -1;
    for (int i = nums.length - 1; i > 0; i--) {
      if (nums[i] > nums[i - 1]) {
        mark = i - 1;
        break;
      }
    }

    if (mark == -1) {
      reverse(nums, 0, nums.length - 1);
      return;
    }

    int idx = nums.length - 1;
    for (int i = nums.length - 1; i >= mark + 1; i--) {
      if (nums[i] > nums[mark]) {
        idx = i;
        break;
      }
    }

    swap(nums, mark, idx);

    reverse(nums, mark + 1, nums.length - 1);
  }

  private static void swap(int[] nums, int i, int j) {
    int t = nums[i];
    nums[i] = nums[j];
    nums[j] = t;
  }

  private static void reverse(int[] nums, int i, int j) {
    while (i < j) {
      swap(nums, i, j);
      i++;
      j--;
    }
  }

  public static void Initialize(int n) {
    N = n;
    ft = new int[N + 2];
    orig = new int[N + 1];
  }

  public static void reset(){
    Arrays.fill(ft, 0);
    Arrays.fill(orig, 0);
  }

  public static void update(int x) {
    for (int i = x + 1; i <= N + 1; i += (i & (-i))) {
      ft[i]++;
    }
    orig[x] = 1;
  }

  public static long getSum(int x) {
    long sum = 0L;
    for (int i = x + 1; i > 0; i -= (i & (-i))) {
      sum += (long)ft[i];
    }
    return sum;
  }

  public static long calcInversion(int[] input) {
    int n = input.length;
    long inversionCount = 0;
    for (int i = n - 1; i >= 0; i--) {
      inversionCount += getSum(input[i]);
      update(input[i]);
    }
    return inversionCount;
  }

  private static int gcdThing(int a, int b) {
    BigInteger b1 = BigInteger.valueOf(a);
    BigInteger b2 = BigInteger.valueOf(b);
    BigInteger gcd = b1.gcd(b2);
    return gcd.intValue();
  }

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

  static class FastScanner {

    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");

    String next() {
      while (!st.hasMoreTokens()) {
        try {
          st = new StringTokenizer(br.readLine());
        } catch (IOException e) {
          e.printStackTrace();
        }
      }
      return st.nextToken();
    }

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

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

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