/*
	0130:Train
*/
#include	<iostream>
#include	<vector>
#include	<string>
#include	<utility>
#include	<algorithm>

using namespace std;

typedef vector< pair<int, char> > VpIC;

string solve(string hoge);

int main(void) {
	int data;
	
	cin >> data;
	for(int i = 0; i < data; i++) {
		string aaa;
		
		cin >> aaa;
		cout << solve(aaa) << endl;
	}
	
	return 0;
}

string solve(string hoge) {
	string::iterator it = hoge.begin();
	string ans;
	int rank = 0, count = 0;
	VpIC list;
	int piyo[26] = { 0 };
	
	while( it != hoge.end() ) {
		if(*it == '-') {
			rank--;
			it++;	it++;
		} else if(*it == '<') {
			rank++;
			it++;	it++;
		} else {
			if( piyo[*it - 'a'] == 0) {
				list.push_back( pair<int, char>(rank, *it) );
				piyo[*it - 'a'] = 1;
				count++;
			}
			it++;
		}
	}
	sort(list.begin(), list.end());
	for(int i = count-1; i >= 0; i--) {
		ans += list[i].second;
	}
	
	return ans;
}