#include<iostream>
using namespace std;
void solve(string buf){
	string ans="";
	ans+=buf[0];
	int target=0;
	for(string::iterator it=buf.begin()+1;it!=buf.end();){
		//cout<<"ans:"<<ans<<endl;
		//cout<<*it<<endl;
		if(*it=='<'){
			it+=2;
			string tmp="";
			if(target-1<0){
				tmp+=*it;
				tmp+=ans;
				ans=tmp;
			}
			else{
				target--;
			}
			it++;
		}
		else if(*it=='-'){
			it+=2;
			if(target+1>=ans.size())ans+=*it;
			target++;
			it++;
		}
	}
	cout<<ans<<endl;

}
int main(){
	int d;
	
	string buf;
	cin>>d;
	for(int i=0;i<d;i++){
		cin>>buf;
		solve(buf);
	}
	return 0;
}