#include <bits/stdc++.h>
using namespace std;

#define PI 3.14159265
#define pb push_back
#define vi vector<int>
#define mod 1000000007
#define inf 1e18
#define int int64_t
#define setbits(x) __builtin_popcountll(x)
#define pii pair<int, int>
#define mp make_pair




#define rep(i,x,y) for(i=x;i<=y;i++)
#define _rep(i,x,y) for(i=x;i>=y;i--)



#define w(x) \
   int x;    \
   cin >> x; \
   while (x--)

typedef long long ll;


void gk()
{
   ios_base::sync_with_stdio(0);
   cin.tie(0);
   std::cout.tie(0);

#ifndef ONLINE_JUDGE
   freopen("input.txt", "r", stdin);
   freopen("output.txt", "w", stdout);
#endif
}





int row[4] = {1, -1, 0, 0};
int col[4] = {0, 0, -1, 1};
// const int sz = 1e7+1;



int find_p(int x, vector<int>&parent) {
   return x^parent[x]?parent[x] = find_p(parent[x], parent):x;
}

bool join(int x, int y, vector<int>&parent) {
   if((x=find_p(x,parent)) == (y=find_p(y, parent)))
     return 0;

     parent[x] = y;
     return 1;
}


const int sz = 1e5+2;
int prime[sz];

void sieve() {
   prime[0] = 1;
   prime[1] = 1;
   for(int i=2;i*i<sz;i++) {
      if(!prime[i]) {
         for(int j=2*i;j<sz;j+=i) {
            prime[j] = 1;
         }
      }
   }

}
int distinct(string s) {

sort(s.begin(), s.end());
return unique(s.begin(), s.end()) - s.begin();

}

string can(const string &s, char c) {
   int f = 0;
  string t = "";
  for(char a:s) {
     if(a != c && f) {
        t += a;
     } else if(c == a) {
        f = 1;
     }
  }
  return t;
}
void find() {
string s;
cin>>s;
unordered_set<char> table(s.begin(), s.end());
int m = table.size();
string t = "";
char c = -1;

while(m > 0) {
   char cm = -1;
   for(char c:table) {
      if(distinct(can(s, c)) == m-1) {
        cm = max(cm, c);
      }
   }

   t += cm;
   m--;
   s = can(s, cm);

   table.erase(cm);
   
}
cout<<t<<"\n";
}



int32_t main()
{
   ios_base::sync_with_stdio(0);
   cin.tie(0);
   std::cout.tie(0);
// gk();


   int t = 1;
   cin >> t;

   while (t--)
   {
      find();

   }
   return 0;
}
