//author:aTSL
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <vector>
#include <map>
#include <stack>
#include <algorithm>
#include <queue>
#define min(a,b) (a>b?b:a)
#define max(a,b) (a>b?a:b)
#define pii pair<int,int>
typedef long long ll;
using namespace std;
const int N=100005;
const int mod=998244353;
int pos[30],vis[30];
int main() {
  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
  //ifstream s("input.txt");
  //ofstream c("output.txt");
  int n,m;
  int tt;
  cin>>tt;
  while(tt--) {
    stack<char> sta;
    string s;
    cin>>s;
    for(int i=0;i<30;i++) vis[i]=0;
    int n=s.size();
    for(int i=0;i<n;i++) pos[s[i]-'a'+1]=i;
    for(int i=0;i<n;i++) {

      while(!sta.empty()&&pos[sta.top()-'a'+1]>i&&s[i]>sta.top()&&!vis[s[i]-'a'+1]) vis[sta.top()-'a'+1]=0,sta.pop();
      if(!vis[s[i]-'a'+1]) sta.push(s[i]);
      vis[s[i]-'a'+1]=1;
    }
    string ans="";
    while(!sta.empty()) ans=sta.top()+ans,sta.pop();
    cout<<ans<<'\n';
  }
  return 0;
}

/*

*/
