#include <bits/stdc++.h>

using namespace std;

//Warsaw debug template
#define LOCAL
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
    enable_if<sizeof dud<c>(0) x 1,debug&>::type operator<<(c i){
sim > struct rge {c b,e;};
sim > rge<c> range(c i, c j) {return rge<c>{i,j};}
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug{
#ifdef LOCAL
~debug() {cerr<<endl; }
eni(!=) cerr<< boolalpha << i; ris;}
eni(==) ris <<range(begin(i),end(i)); }
sim, class b dor(pair<b,c> d){
ris<<"("<<d.first<<","<<d.second<<")";
}
sim dor(rge<c> d){
    *this << "[";
    for(auto it=d.b;it!=d.e;++it)
        *this <<"," +(it==d.b)<< *it;
    ris<<"]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) "["<<#__VA_ARGS__":"<<(__VA_ARGS__)<<"]"
//End of debug template
#define FOR(i,n) for (int i = 0; i < (n); ++i)


using ll = long long;
//codeforces
         //^   
//odfrces

//c o d e f o r c e s 
				  //^ find first occur	
				  //^ pointer from 0 to any s     
		  //^ find occur
		  //^ pointer from 0 to any r
		  //^ from here to sz -1, all chars set to be true

		//^ find occur
//^ pointer from 0 to first o
//check from this index til end insert to be true	
void solve(){
	string s;
	cin >> s;
	int n = s.size(); 
	vector<bool> exists(26);
	FOR(i,n) exists[s[i] - 'a'] = true;
	int idx = 0;
		
	while(true){
		bool isOK = false;
		for(int i = 25; i>=0;i--){
			if(exists[i]){
				int where = idx;
				while(s[where]-'a' != i){
					where++;
				}
				vector<bool> suffix(26);
				for(int j = where;j < n;j++){
				   if(exists[s[j]-'a']){
						suffix[s[j]-'a'] = true;
					}
				}
				if(suffix == exists){
				   cout << s[where];
				   idx = where + 1;
				   exists[s[where] - 'a'] = false;
				   isOK = true;
				   break;
			   }
				
			}
		}
		if(!isOK) break;
	}
	cout << endl;

}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int t;
	cin >> t;
	while(t--){
		solve();
	}
	
	
	return 0;
}



//void solve(){
	//string s;
	//cin>>s;
	//vector<int> h(130),vis(130);
	//vector<char> a;
	//for(auto i:s)h[i]++;
	//for(auto i:s){
		//h[i]--;
		//if(!vis[i]){
			//while(!a.empty()){
				//if(h[a.back()]==0 or a.back()>i)break;
				//vis[a.back()]=0;
				//a.pop_back();
			//}
			//a.push_back(i);
			//vis[i]=1;
		//}
	//}
	//cout<<string(a.begin(),a.end())<<"\n";
//}
//int main()
//{
	//int t;cin>>t;
	//while(t--)solve();
//}
