#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define INF 1000000000000000000
#define llu unsigned long long int
#define pb push_back
#define ff first
#define ss second
long long mod=1000000007;
/*
bool comparator(const pair<vector<int>,int> a,const pair<vector<int>,int> b)
{
return a.ff.size()<b.ff.size();
}
*/
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t,i,n,j,f,k,k1,start,c1=0,ii;
cin>>t;
while(t--)
{
  string s;
  cin>>s;
  c1++;
  n=(int)s.size();
  char b[n],ans[n];
  int dp[n];
  set <char> s1,s2;
  for(i=0;i<n;i++)
  s1.insert(s[i]);
  for(i=n-1;i>=0;i--)
  {
    s2.insert(s[i]);
    dp[i]=s2.size();
  }
  k=0;
  for(auto &it: s1)
  b[k++]=it;
  k1=0;
  start=0;
  while(s1.size()!=0)
  {
  for(i=k-1;i>=0;i--)
  {
    f=0;
    for(j=n-1;j>=start;j--)
    {
      if(s[j]==b[i])
      {
        if(dp[j]==s1.size())
        {
          ans[k1++]=s[j];
          f=1;
          for(ii=start;ii<=j;ii++)
          if(s[ii]==s[j])
          break;
          start=ii+1;
          break;
        }
      }
    }
    if(f==1)
    break;
  }
  string tmp="";
  for(i=0;i<n;i++)
  {
  if(i<start)
  tmp+=s[i];
  else
  {
    if(s[i]==ans[k1-1])
    continue;
    else
    tmp+=s[i];
  }
  }
  s1.erase(ans[k1-1]);
  k=0;
  for(auto &it: s1)
  b[k++]=it;
  s=tmp;
  n=(int)s.size();
  s2.clear();
  for(i=n-1;i>=start;i--)
  {
    s2.insert(s[i]);
    dp[i]=s2.size();
  }
  //cout<<ans[k1-1]<<" "<<s<<endl;
  }
  for(i=0;i<k1;i++)
  cout<<ans[i];
  cout<<endl;
}
}