/*
######################################################################################
#                                                                                    # 
#                            ,.--------._                                            #
#                           /            ''.                                         #
#                         ,'                \     |"\                /\          /\  #
#                /"|     /                   \    |__"              ( \\        // ) #
#               "_"|    /           z#####z   \  //                  \ \\      // /  #
#                 \\  #####        ##------".  \//                    \_\\||||//_/   #
#                  \\/-----\     /          ".  \                      \/ _  _ \     #
#                   \|      \   |   ,,--..       \                    \/|(O)(O)|     #
#                   | ,.--._ \  (  | ##   \)      \                  \/ |      |     #
#                   |(  ##  )/   \ `-....-//       |///////////////_\/  \      /     #
#                     '--'."      \                \              //     |____|      #
#                  /'    /         ) --.            \            ||     /      \     #
#               ,..|     \.________/    `-..         \   \       \|     \ 0  0 /     #
#            _,##/ |   ,/   /   \           \         \   \       U    / \_//_/      #
#          :###.-  |  ,/   /     \        /' ""\      .\        (     /              #
#         /####|   |   (.___________,---',/    |       |\=._____|  |_/               #
#        /#####|   |     \__|__|__|__|_,/             |####\    |  ||                #
#       /######\   \      \__________/                /#####|   \  ||                #
#      /|#######`. `\                                /#######\   | ||                #
#     /++\#########\  \                      _,'    _/#########\ | ||                #
#    /++++|#########|  \      .---..       ,/      ,'##########.\|_||                #
#   //++++|#########\.  \.              ,-/      ,'########,+++++\\_\\               #
#  /++++++|##########\.   '._        _,/       ,'######,''++++++++\                  #
# |+++++++|###########|       -----."        _'#######' +++++++++++\                 #
# |+++++++|############\.     \\     //      /#######/++++ S@yaN +++\                #
#      ________________________\\___//______________________________________         #
#     / ____________________________________________________________________)        #
#    / /              _                                             _                #
#    | |             | |                                           | |               #
#     \ \            | | _           ____           ____           | |  _            #
#      \ \           | || \         / ___)         / _  )          | | / )           #
#  _____) )          | | | |        | |           (  __ /          | |< (            #
# (______/           |_| |_|        |_|            \_____)         |_| \_)           #
#                                                                                    #
######################################################################################

                           .e@$$$$$$$eeeu=~=._
                        zd$$$$$$$$$$$$$$'   z$b..  _,x,
                     z????$$$$$$$$P",-==   dP""`$$$.  .;
                  .e"..     `"?$Fu^'e$$$$$be.   )$$' 4r'$$nn,     _. -
                ud$$$P  zeeeu.   ld$$$$$$$$$$$$c`=._,$$  <"$$$$= '
              z$$$$$$e ?$$"   "FE=e2R$$$$$$$$$$$$bu"h._..d. "`nMb`    _
           .-J$$$$$$$$,?$$b,.,J",xc3$$$$$$$$$$$$$$$" Mh. "  'MMMMP- ~
      ..ze$F R$$$$$$$$$bcccd$$"J(T-
"b".nMMP'b.   "",c$$$$$$$$P.MMMMMMMb.<       )!! >'dMMMMMMM  __
 .HMMMM  "??$$$$$PF"uPF",, umnmnHMMMMMbx.... ''.n'MMMMMCund~    `~ ~ -
'M'HMMMh         .e$ee$$?7 MMMMMT"",MMMMMMMMMMMMM.MMMMMMMMM
  MMMMMMMx -...e$$$P??,nMM "`,nndMMMMMMMMMMMMMMMMk`MMMMMMMP
 H"MMMMMMMMhx???",nHMMP",nh MMMMMM?MP"xHMMMMMMMMMF-?TMMMM"
   MMPTMMMMMMMMMMP"u- :n.`"%'MF.xnF.nMMMMMMMMMP".::::."Te
  'M".MPTMMMMMP"zeEeP.MMMMM"..4MF,HMMMMMMMMMF'.::::::::`R.
   " MF dMMMf z$$$$$ MMMF'xMMMr`HMMMMMMMMM".:::::::.::...?_
     T  M P  $$$$$$%dMF'dMMMM"xk'MPJMMMMP ::'.'';i!!!!'`^.xhMmx
       'M   4$$$$$P.P,HMMMMM,HMMh TMMMMM> :!!!!!!!'`.xnMMMMMMMMMn
            J$$$$$ ",MMMMMM,MMMM'h TMMMML'!;!!!`.nHMMMMMMMMMMMMMMMn
            $$$$$P HMMMMMM,MMMM MMM."MMMM \!i`.HMMMMMMMMMMMMMMMMMMMMr
            $$$$$"dMMMMMMMMMMMfdMMMM.`MMMh   xMMMMMMMMMMMMMMMMMMMMMMM
           4$$$$$ MMMMMMMMMMMMMMMMMMMx`MMMMMMMMMMMMMMMMMMMMMMMMMMMMMM'
          ,4$$$$$.MMMMMMMMMMMMMMMMMMMMh TMMMMMMMMMMMMMMMMMMMMMMMMMMMf
         ; J$$$$F;MMMMMMMMMMMMMMMMMMMMMM."MMMMMMMMMMMMMMMMMMMMMMP""
       .db $$$$$ MMMMMMMMMMMMMMMMMMMMMMMMh."MMMMMMMMMMMMMMPF"
      , d$b$$$$$ MMMMMMMMMMMMMMMMMMMMMMMMMM u"?f""?=
     .  $$$$$$$$ MMMMMMMMMMMMMMMMMMMMMMMMMfJ$b
    z$  d$$$$$$$ MMMMMMMMMMMMMMMMMMMMMMMMM P" `
   e$$h ?$$$$$$$ MMMMMMMMMMMMMMMMMMMMMMMMf^  zF`.
*/



//(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)
//#pragma comment(linker, "/stack:200000000")
//(UNCOMMENT WHEN NEEDED)

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

#pragma GCC optimize("O3")

typedef long long ll;
typedef unsigned long long ull;
const ll mod=1e9+7;
#define eps 1e-7
#define PI 3.1415926535897932384626
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sortall(x) sort(all(x))
#define vpi vector<pi>
#define vi vector<ll>
#define pi pair<ll,ll>
#define mk make_pair
#define pb push_back
#define ppb pop_back
#define umap unordered_map
#define uset unordered_set
#define vvi vector<vector<ll>>
#define minheap priority_queue<ll,vi,greater<ll>>
#define maxheap priority_queue<ll>
#define minheapi priority_queue<pi,vpi,greater<pi>>
#define maxheapi priority_queue<pi>
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL);
#define fo(i, n) for(i=0;i<n;i++)
#define fox(i,a,b) for(i=a;i<b;i++)
#define deb1(x) cout << #x << " = " << x << endl;
#define deb2(x, y) cout << #x << " = " << x << ", " << #y << " = " << y << endl
#define deblp(i, a, n) fo(i, n){cout << a[i] << " ";}
#define clr(x) memset(x, 0, sizeof(x))
#define fills(a,val) fill_n(a, sizeof(a)/sizeof(a[0]), val)

ll powmod(ll x,ll y){ll t; for(t=1;y;y>>=1,x=x*x%mod) if(y&1) t=t*x%mod; return t;}
ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
ll lcm(ll x,ll y){return x*(y/gcd(x,y)); }
ll modd(ll a){return (a%mod + mod)%mod;}
ll add(ll a,ll b){return modd(modd(a)+modd(b));}
ll mul(ll a,ll b){return modd(modd(a)*modd(b));}
int smask(int i,int pos){ return (i|(1<<pos)); }
int clmask(int i,int pos){return (i&(~(1<<pos))) ; }
bool chmask(int i,int pos){return (i&(1<<pos))!=0 ;}
double cordist(pair<double,double> a,pair<double,double> b)
{return sqrt(((a.first-b.first)*(a.first-b.first))+((a.second-b.second)*(a.second-b.second)));}
long long binpow(long long a, long long b) {
    if (b == 0)
        return 1;
    long long res = binpow(a, b / 2);
    if (b % 2)
        return mul(mul(res, res), a);
    else
        return mul(res,res);
}



//ll prime[60];
//int posx[10];
//int posy[10];
//im,q,r;nt price[30]; 
//char board[26][26];
ll n,m,q,r,i,j;
vi arr,brr;


void solve()   
{  
    string s;
    cin>>s;
    n=s.length();
    vector<bool>exist(26,false);
    fo(i,n)
        exist[s[i]-'a']=true;
    int start=0;
    
    while(true)
    {
        bool happn=false;
        for(int use=25;use>=0;use--)
        {
            if(exist[use])
            {
                char c=use+'a';
                int firstoc=start;
                fox(i,start,n)
                    if( s[i]==c)
                    {
                        firstoc=i;
                        break;
                    }
                vector<bool> suff(26,false);
                int x;
                fox(x,firstoc,n)
                    if(exist[s[x]-'a'])
                        suff[s[x]-'a']=true;
                if(exist==suff)
                {
                    exist[use]=false;
                    cout<<c;
                    start=firstoc+1;
                    happn=true;
                    break;
                }

            }
        }
        if(!happn)
            break;
    }

    cout<<endl; 
}

 
int main()  
{
    IOS
    #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.in", "r", stdin);
    // for writing output to output.txt
    freopen("output.out", "w", stdout);
    #endif
    
    int k=1;
    cin>>k;
    
    //sieve();
    //int counter=1;
    while(k--)
    {
        //printf("Case #%d: ",counter++);
        solve();
    }
    return 0;
}