#include<iostream>
#include<string>
using namespace std;
int main(void){
	int n;

	cin >> n;
	for(int i = 0; i < n; ++i){
		int nowPos = 0;
		int dir = 0;
		string train;
		string s;
		cin >> s;

		train += s[0];
		for(unsigned int j = 1; j < s.length(); ++j){
			if( s[j] == '<' ){
				--nowPos;
				++j;
			}else if( s[j] == '-' ){
				++nowPos;
				++j;
			}else{
				if( nowPos >= (signed)train.length() ){
					train += s[j];
					nowPos = train.length() - 1;
				}else if( nowPos < 0 ){
					train.insert( train.begin(), s[j] );
					nowPos = 0;
				}
			}
		}
		cout << train << '\n';
	}
	return 0;
}