#include <iostream>
#include <string>
#include <list>
#include <algorithm>
using namespace std;

int main(){
	int n;
	string str;
	list< char > lst;
	
	cin >> n;
	
	for(int i = 0; i < n; ++i){
		cin >> str;
		bool dir = false;
		lst.clear();
		
		for(int j = 0; j < str.length(); ++j){
			char ch = str[j];
			
			if(ch >= 'a' && ch <= 'z'){
				if(find(lst.begin(), lst.end(), ch) == lst.end()){
					if(dir){
						lst.push_front(ch);
					}else{
						lst.push_back(ch);
					}
				}
			}else if(ch == '<'){
				dir = true;
			}else if(ch == '>'){
				dir = false;
			}
		}
		
		for(list< char >::iterator it = lst.begin(); it != lst.end(); ++it){
			cout << (char)(*it);
		}
		cout << endl;
	}
	return 0;
}