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

#define rep(i,n)    for(int i = 0; i < (n); i++)
#define repi(i,a,b) for(int i=(a); i<= (b); i++)
#define repA(i,n)   for(int i = (n); i >= 0; i--)
#define pb push_back
#define sz(s) (int)((s).size())
#define all(s) (s).begin(),(s).end()
#define ff first
#define ss second

typedef long long ll;
ll mod = (ll)(1e9+7);

int aux() {

}

void pre() {

}

void solve() {
  string s; cin>>s;
  int n = sz(s);
  int cnt[26],taken[26];
  rep(i,26) cnt[i] = 0,taken[i] = false;

  rep(i,n)  cnt[(int)(s[i] - 'a')]++;

  stack<char> st;
  int cur = 0;
  st.push(s[cur]);
  cnt[(int)(s[cur]-'a')]--;
  taken[(int)(s[cur]-'a')] = true;
  cur++;

  string a = "codfers";

//  for(auto i:a) cout<<i<<" ";  cout<<"\n";

  while(cur < n)  {
    if(taken[(int)(s[cur]-'a')])  {
      cnt[(int)(s[cur]-'a')]--;
      cur++;continue;
    }

    if(st.top() > s[cur]) {
      st.push(s[cur]);
      taken[(int)(s[cur]-'a')] = true;
      cnt[(int)(s[cur]-'a')]--;
      cur++;continue;
    }

    while(!st.empty() and st.top() < s[cur] and cnt[(int)(st.top()-'a')] >= 1) {
      taken[st.top() - 'a'] = false;
      st.pop();
    }
    st.push(s[cur]);
    cnt[(int)(s[cur]-'a')]--;
    taken[(int)(s[cur]-'a')] = true;
    cur++;

//    for(auto i:a) cout<<taken[(int)(i-'a')]<<" "; cout<<"\n";
  }

  string ans = "";
  while(!st.empty())  {
    ans = st.top() + ans;
    st.pop();
  }
  cout<<ans;

}

int main() {
  #ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  #endif

  ios_base::sync_with_stdio(false);
  cin.tie(0);cout.tie(0);

  pre();

  int t = 1;
  cin>>t;

  for(int i=1; i<=t; i++)  {
    //cout<<"Case #"<<t<<":\n";
    solve();
    cout<<"\n";
  }
  return 0;
}
