#include <bits/stdc++.h>
 
using namespace std;
 
void solve() {
  string s;
  cin >> s;
  array<int, 26> freq{};
  for (int i = 0; i < s.size(); ++i)
    ++freq[s[i] - 'a'];
  auto advance = [&](int p) -> int {
    int best = -1, loc = -1;
    array<int, 26> cnt{};
    for (int i = p; i < s.size(); ++i) {
      if (!s[i]) continue;
      if (s[i] - 'a' > best) {
        best = s[i] - 'a';
        loc = i;
      }
      ++cnt[s[i] - 'a'];
      if (cnt[s[i] - 'a'] == freq[s[i] - 'a']) break;
    }
    if (loc == -1) return (int) s.size();
    for (int i = p; i < loc; ++i) {
      if (s[i]) {
        --freq[s[i] - 'a'];
      }
    }
    for (int i = loc + 1; i < s.size(); ++i) {
      if (s[i] == best + 'a') {
        s[i] = 0;
      }
    }
    freq[best] = 1;
    return loc;
  };
  int p = 0;
  string ans;
  while (true) {
    p = advance(p);
    if (p == s.size()) break;
    ans += s[p];
    ++p;
  }
  cout << ans << "\n";
}
 
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int t; cin >> t; while (t--) solve();
  return 0;
}
