#include<iostream>
#include<string>
using namespace std;
int main()
{
	string s,r;
	int i,train,n;
	cin >> n;
	while(n--)
	{
		cin >> s;

		r="";
		train=0;
		r+=s[0];

		for(i=1;i<s.size(); i+=3)
		{
			if(s[i]=='-')
			{
				if(train==r.size()-1)
					r.push_back(s[i+2]);
				++train;
			}
			else
			{
				if(train==0)
					r.insert(r.begin(),s[i+2]);
				else
					--train;
			}
		}
		cout << r << endl;
	}
	return 0;
}