#include<iostream>
#include<deque>
#include<string>
using namespace std;

int main(){
	int n;
	cin>>n;
	while(n--){
		deque<char> deq;	
		string s;
		cin>>s;
		int p=0;
		deq.push_front(s[0]);
		for(int i=1;i<s.size();i+=3){
			if(s[i]=='<'){
				if(p==0)deq.push_front(s[i+2]);
				else p--;
			}else{
				if(p+1==deq.size())deq.push_back(s[i+2]);
				p++;
			}
		}
		for(int i=0;i<deq.size();i++)cout<<deq[i];
		cout<<endl;
	}
	return 0;
}