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 CPP):

Solution:
// Problem: D. Kill Anton
// Contest: Codeforces - Codeforces Round #723 (Div. 2)
// URL: https://codeforces.com/contest/1526/problem/D
// Memory Limit: 512 MB
// Time Limit: 2000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt,tune=native")
//#pragma GCC optimize(2)
#include<cstdio>
#include<iostream>
#include<string>
#include<cstring>
#include<map>
#include<cmath>
#include<cctype>
#include<vector>
#include<set>
#include<queue>
#include<assert.h>
#include<algorithm>
#include<sstream>
#include<ctime>
#include<cstdlib>
#define X first
#define Y second
#define L (u<<1)
#define R (u<<1|1)
#define pb push_back
#define mk make_pair
#define Mid ((tr[u].l+tr[u].r)>>1)
#define Len(u) (tr[u].r-tr[u].l+1)
#define random(a,b) ((a)+rand()%((b)-(a)+1))
#define db puts("---")
using namespace std;

//void rd_cre() { freopen("d://dp//data.txt","w",stdout); srand(time(NULL)); }
//void rd_ac() { freopen("d://dp//data.txt","r",stdin); freopen("d://dp//AC.txt","w",stdout); }
//void rd_wa() { freopen("d://dp//data.txt","r",stdin); freopen("d://dp//WA.txt","w",stdout); }

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> PII;

const int N=100010,mod=1e9+7,INF=0x3f3f3f3f;
const double eps=1e-6;

string s,ps;
string mp[10];
int a[20];
vector<int>v[20];
struct Node {
	int l,r;
	LL cnt,lazy;
}tr[N<<2];

void pushup(int u) {
	tr[u].cnt=tr[L].cnt+tr[R].cnt;
}

void pushdown(int u) {
	if(!tr[u].lazy) return;
	LL lazy=tr[u].lazy; tr[u].lazy=0;
	tr[L].lazy+=lazy; tr[R].lazy+=lazy;
	tr[L].cnt+=lazy*Len(L); tr[R].cnt+=lazy*Len(R);
}

void build(int u,int l,int r) {
	tr[u]={l,r,0,0};
	if(l==r) {
		tr[u].cnt=l;
		return;
	}
	build(L,l,Mid); build(R,Mid+1,r);
	pushup(u);
} 

void change(int u,int l,int r,int c) {
	if(tr[u].l>=l&&tr[u].r<=r) {
		tr[u].cnt+=c;
		tr[u].lazy+=c;
		return;
	}
	pushdown(u);
	if(l<=Mid) change(L,l,r,c);
	if(r>Mid) change(R,l,r,c);
}

LL query(int u,int pos) {
	if(tr[u].l==pos&&tr[u].r==pos) return tr[u].cnt;
	LL ans=0;
	pushdown(u);
	if(pos<=Mid) return query(L,pos);
	else return query(R,pos);
}

LL check(string ps) {
	LL ans=0;
	build(1,1,(int)ps.length());
	for(int i=0;i<4;i++) v[i].clear();
	for(int i=ps.length()-1;i>=0;i--) {
		if(ps[i]=='A') v[0].pb(i+1);
		else if(ps[i]=='N') v[1].pb(i+1);
		else if(ps[i]=='O') v[2].pb(i+1);
		else v[3].pb(i+1);
	}
	for(int i=0;i<s.length();i++) {
		int pos=-1;
		if(s[i]=='A') pos=v[0].back(),v[0].pop_back();
		else if(s[i]=='N') pos=v[1].back(),v[1].pop_back();
		else if(s[i]=='O') pos=v[2].back(),v[2].pop_back();
		else pos=v[3].back(),v[3].pop_back();
		LL now=query(1,pos);
		ans+=now-(i+1);
		assert(pos>=1);
		change(1,1,pos,1);
	}
	return ans;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int _; cin>>_;
	while(_--) {
		for(int i=0;i<4;i++) mp[i]="",a[i]=i;
		cin>>ps; s=ps;
		for(int i=0;i<ps.length();i++) {
			if(ps[i]=='A') mp[0]+='A';
			else if(ps[i]=='N') mp[1]+='N';
			else if(ps[i]=='O') mp[2]+='O';
			else mp[3]+='T';
		}
		LL ans=-1;
		string res;
		do {
			string now="";
			for(int i=0;i<4;i++) now+=mp[a[i]];
			LL x=check(now);
			if(x>ans) ans=x,res=now;
		}while(next_permutation(a,a+4));
		cout<<res<<endl; 
	}



	return 0;
}
/*

*/