#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define pb emplace_back 
#define mp make_pair
#define fi first
#define se second
#define all(v) v.begin(),v.end()
#define run ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);cerr.tie(0);
#define mod 1000000007
#define decimal(n,k) cout<<fixed<<setprecision(k)<<n<<endl
#define LL_MAX LLONG_MAX
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define maxa(v) *max_element(v, v + v.size())
#define mina(v) *min_element(v, v + v.size())
int exp(int x,int y){int res=1;x=x%mod;while(y>0){if(y&1)res=(res*x)%mod;y=y>>1;x=(x*x)%mod;}return res;}
int modinv(int x){return exp(x,mod-2);}
int add(int a,int b){a%=mod,b%=mod;a=((a+b)%mod+mod)%mod;return a;}
int sub(int a,int b){a%=mod,b%=mod;a=((a-b)%mod+mod)%mod;return a;}
int mul(int a,int b){a%=mod,b%=mod;a=((a*b)%mod+mod)%mod;return a;}
int gcd(int a, int b){if (b == 0)return a; return gcd(b, a % b);}
int Log2n( int n){ return (n > 1) ? 1 + Log2n(n / 2) : 0;} 
int fac[100009];int ncr_mod(int n,int k){int ans=fac[n];ans*=modinv(fac[k]);ans%=mod;ans*=modinv(fac[n-k]);ans%=mod;return ans;}
vector<int>v_prime;void Sieve(int n){bool prime[n + 1];memset(prime,true,sizeof(prime));for (int p = 2; p*p <=n;p++){if(prime[p] ==true) {for(int i = p*p; i<= n; i += p)prime[i]=false;}}for(int p = 2;p<= n;p++)if (prime[p])v_prime.pb(p);}
vector<int>v_factor;void factors(int n){ for (int i=1; i<=sqrt(n); i++) {if (n%i == 0) {if (n/i == i) v_factor.pb(i);else { v_factor.pb(i),v_factor.pb(n/i);};} } sort(all(v_factor)); } 
void out(vector<int>&a){for(int i=0;i<a.size();i++) cout<<a[i]<<" ";  cout<<endl;} 


// s.top().second;


signed main()
 {


       run;


/*
open for mod factorial

     fac[0]=1;
       for(int i=1;i<100009;i++)
      {
         fac[i]=fac[i-1]*i; 
          fac[i]%=mod;  
      }
 */


/*
for sieve open this and use v_prime

       int pp=pow(10,6)+100000; 
          Sieve(pp);

*/


 // USE v_factor For calculating factors                       


int  t=1;
 cin>>t;
 while(t--)
{
         // vector< pair <int,int> > vp; 
        //  map<int,int>mp; // x.second-->frequency
       //   set<int>st;


          int  n,i,x,y,ok=0,sum=0,ans=0,j,k,cnt=0,m,c=0;
          int  h[26]={0};




                string s,s1;
                   cin>>s;


        
              n=(int)s.size();
              char ch1='Z';

              for(i=0;i<n;i++)
              {
                  if(ch1!=s[i])
                  {
                      s1+=s[i];
                      ch1=s[i];
                  }
              }



          

              n=(int)s1.size();
              s=s1;
           

              for(i=0;i<n;i++)
              {
                  h[s[i]-'a']++;
              }
              int h1[26]={-1};

              for(i=0;i<n;i++)
              {
                  h1[s[i]-'a']=i;
              }

              string sx;

              for(i=0;i<n;i++)
              {
                 if(h[s[i]-'a']==1)
                 {
                     sx+=s[i];
                     h[s[i]-'a']--;

                 }
                 else
                 {


                        char ch='A';
                     for(j=i;j<n;j++)
                     {

                         if(h[s[j]-'a']>0)
                         {

                             if(h1[s[j]-'a']==j&&h[s[j]-'a']>1)
                            {
                                break;
                            }

                                    if(h[s[j]-'a']==1)
                                    {
                                        ch=max(ch,s[j]);

                                        break;
                                    }
                                    ch=max(ch,s[j]);
                         }
                     }

                    // cout<<ch<<" "<<sx<<endl;


                     for(j=i;j<n;j++)
                     {
                         if(s[j]==ch)
                         {
                             h[s[j]-'a']=0;
                             sx+=ch;
                             break;

                         }
                         h[s[j]-'a']--;
                         
                     }
                     i=j-1;





                 }
              }

              cout<<sx<<endl;

            

            
}
}