#include <iostream>
using namespace std;
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;++i){
		string s,ss;
		cin>>s;
		int p=0;
		for(int j=0;j<s.size();++j){
			if(s[j]=='>')++p;
			else if(s[j]=='<')--p;
			else if('a'<=s[j]&&s[j]<='z'){
					if(p==-1){
						ss=s[j]+ss;
						p=0;
					}else if(p==ss.size())ss=ss+s[j];
			}
		}
		cout<<ss<<"\n";
	}
	return 0;
}