#include<iostream>
#include<stack>
#include<string>
#include<set>
#include<map>
#include<vector>
#include<math.h>
#include<functional>
#include<limits.h>
#include<utility>
#include<queue>
#include<algorithm>
#include<cstring>
#include<iomanip>
#define lowbit(x) ((x)&(-x))

typedef long long ll;
//
const int maxn = 2e5 + 10;
const int maxm = 1e6 + 10;
const int inf = 0x3f3f3f3f;
const ll mod = 1e9 + 7;
const double eps = 1e-7;
using namespace std;
typedef pair<int, int> pii;
int dir[4][2] = { { 0,1 },{ 0,-1 },{ 1,0 },{ -1,0 } };

string s, ans;
int n;
vector<int> p[26];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int T;
	cin >> T;
	while (T--)
	{
		cin >> s;
		ans.clear();
		for (int i = 0;i < s.size();i++)
			p[s[i] - 'a'].push_back(i);
		int cnt = 0;
		for (int i = 0;i < 26;i++)
			if (p[i].size()) cnt++;
		int lst = 0;
		for (int i = 0;i < cnt;i++)
		{
			for (int j = 25;j >= 0;j--)
			{
				char c = j + 'a';
				if (p[j].size() == 0) continue;
				bool ok = true;
				int x=lower_bound(p[j].begin(), p[j].end(), lst) - p[j].begin();
				x = p[j][x];
				for (int z = 25;z >= 0;z--)
					if (z != j&&p[z].size() && p[z][p[z].size() - 1] < x)
					{
						ok = false;
					}
				if (ok)
				{
					ans.push_back(c), p[j].clear();
					lst = x;
					break;
				}
			}
		}
		cout << ans << endl;
	}
	return ~~(0 - 0);
}