#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define endl '\n'
#define int long long
#define float long double
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;

const int MAXN = 1e6;

int n;

int t[MAXN];

void modify(int i, int x) {
  t[i += n] = x;
  for (i >>= 1; i >= 1; i >>= 1) {
    t[i] = min(t[i << 1], t[i << 1 | 1]);
  }
}

int query(int l, int r) {
  int ans = 1e9;
  for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
    if (l & 1) {
      ans = min(ans, t[l++]);
    }
    if (r & 1) {
      ans = min(ans, t[--r]);
    }
  }
  return ans;
}

void solve() {
  string s;
  cin >> s;
  n = s.size();
  for (int i = 0; i < n; ++i) {
    s[i] -= 'a';
  }
  vector<vector<int>> v(26);
  for (int i = 0; i < n; ++i) {
    v[s[i]].push_back(i);
  }
  for (int i = 0; i < n; ++i) {
    t[n + i] = v[s[i]].back();
  }
  for (int i = n - 1; i >= 1; --i) {
    t[i] = min(t[i << 1], t[i << 1 | 1]);
  }
  string ans;
  int deleted = 0;
  vector<int> used(26, 0);
  for (int i = 0; i < n; ++i) {
    for (int i = 25; i >= 0; --i) {
      while (!v[i].empty() && v[i].front() < deleted) {
        v[i].erase(v[i].begin());
      }
      if (!used[i] && !v[i].empty() &&
          query(deleted, v[i].front()) > v[i].front()) {
        deleted = v[i].front() + 1;
        ans.push_back(i);
        used[i] = 1;
        for (const int &j : v[i]) {
          modify(j, 1e9);
        }
        v[i].clear();
        break;
      }
    }
  }
  for (int i = 0; i < ans.size(); ++i) {
    ans[i] += 'a';
  }
  cout << ans << endl;
}

#ifdef int
#undef int
int
#define int long long
#else
int
#endif
main() {
  // cin.tie(NULL);
  // cout.tie(NULL);
  // ios_base::sync_with_stdio(false);
  int t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
}
