#include <bits/stdc++.h>
using namespace std;
int main(){
	char train[2048];
	int n;
	cin>>n;
	while(n--){
		int x=0;
		string s,ans;
		cin>>s;
		ans+=s[0];
		for(int i=0;i<(s.length()-1)/3;i++){
			int k=i*3+1;
			if(s[k]=='<'){
				if(x==0){
					string tmp=s[k+2]+ans;
					ans=tmp;
				}else x--;
			}else if(s[k+1]=='>'){
				if(ans[x+1]!=s[k+2]){
					ans+=s[k+2];
					x++;
				}else x++;
			}
		}
		cout<<ans<<endl;
	}
}