#include<iostream>
#include<deque>
using namespace std;
main()
{
	int t;cin>>t;
	for(;t--;)
	{
		string s;cin>>s;
		deque<char>a;
		a.push_back(s[0]);
		int d=0;
		for(int i=1;i<s.size();i+=3)
		{
			if(s.substr(i,2)=="->")
			{
				if(d+1>=a.size())
				{
					a.push_back(s[i+2]);
				}
				d+=1;
			}
			else
			{
				if(d==0)a.push_front(s[i+2]);
				else d-=1;
			}
		}
		for(int i=0;i<a.size();i++)cout<<a[i];
		cout<<endl;
	}
}

