#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize ("O3", "omit-frame-pointer","inline")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.2,fma,popcnt,abm,mmx,avx,avx2,tune=native")

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

/***********************************************/
/* Dear online judge:
 * I've read the problem, and tried to solve it.
 * Even if you don't accept my solution, you should respect my effort.
 * I hope my code compiles and gets accepted.
 *  ___  __     _______    _______      
 * |\  \|\  \  |\  ___ \  |\  ___ \     
 * \ \  \/  /|_\ \   __/| \ \   __/|    
 *  \ \   ___  \\ \  \_|/__\ \  \_|/__  
 *   \ \  \\ \  \\ \  \_|\ \\ \  \_|\ \ 
 *    \ \__\\ \__\\ \_______\\ \_______\
 *     \|__| \|__| \|_______| \|_______|
 */
const long long mod = 1000000007;
//const long long mod = 998244353;
mt19937 rng((int) chrono::steady_clock::now().time_since_epoch().count());

const int mxN = 1010;

int main(int argc, char *argv[]) {
#ifdef ONLINE_JUDGE
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
#endif

	srand(time(NULL));
	cout << fixed << setprecision(9);

	int t = 1;
//	int Case = 1;
	cin >> t;
//	t = 10000;
	while (t--) {
		int n;
		string s, o;
		cin >> s;
		n = (int) s.size();
		vector<vector<int> > hv(30);
		vector<int> ch(30);
		for (int i = 0, j = 0; i < n; i = j) {
			while (j < n && s[i] == s[j])
				j++;
			hv[s[i] - 'a'].push_back(o.size());
			o += s[i];
		}
		s = o;
		n = (int) s.size();
		o = "";
		int c = count_if(hv.begin(), hv.end(), [](vector<int> f) {return !f.empty();});
		for (int it = 0, lst = -1; it < c; it++) {
			for (int i = 29; i >= 0; i--) {
				if (hv[i].empty()) continue;
				if (find(begin(o), end(o), i + 'a') != end(o)) continue;
				int it = lower_bound(begin(hv[i]), end(hv[i]), lst) - begin(hv[i]);
				if (it >= (int) hv[i].size()) continue;
				int to = hv[i][it];
				bool f = true;
				for (int j = 0; j < 30; j++)
					if (!hv[j].empty()) {
						f &= find(begin(o), end(o), j + 'a') != end(o) || hv[j].back() >= to;
					}
				if (f) {
					lst = to;
					o += i + 'a';
					break;
				}
			}
		}
		cout << o << '\n';
	}
	return 0;
}

/* stuff you should look for:
 * overflow, array bounds
 * special cases (n=1?)
 * clear arrays
 * DON'T STICK TO ONE APPROACH
 * solve simpler or different variation
 * Solve DP using graph ( \_(-_-)_/ )
 */
