#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <sstream>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <numeric>
#include <cmath>
#include <climits>
#include <limits>
#include <cfloat>
#include <fstream>
using namespace std;

bool issame (deque<char> train, char c )
{
	deque<char>::iterator it = train.begin();
	for (; it != train.end(); ++it){
		if ((*it) == c ){
			return true;
		} // end if
	} // end for

	return false;
}

int main()
{
//	cut here before submit 
//	freopen ("testcase.train", "r", stdin );
	string str = "";
	int n;

	while (getline (cin, str ) ){
		stringstream ssn(str);
		ssn >> n;
		if (n == 0 ){
			break;
		} // end if
		int i,j;
	
		for (i = 0; i < n; ++i){

			deque<char> train;

			getline (cin, str );

			int len = str.length();
			str += 'E';
			train.push_back(str[0]);
			
			for (j = 1; j < len - 1; ++j){
				if (str[j] != '<' && str[j] != '>' && str[j] == 'E'){
					continue;
				} // end if
				if (str[j] == '>'){
					if (!issame(train, str[j+1] ) ) {
						train.push_back(str[j+1]);
					} // end if
				}else if (str[j] == '<'){
					if (!issame(train, str[j+2] ) ) {
						train.push_front(str[j+2]);
					} // end if
				} // end if
			} // end for

			// train output
			deque<char>::iterator it = train.begin();
			for (; it != train.end(); ++it){
				cout << (*it);
			} // end for
			cout << endl;
			train.clear();
		} // end for

	} // end loop
		
	return 0;
}