#include<iostream>
#include<deque>
#include<string>

int main()
{
	std::deque<char> train;
	std::string str;
	int n;
	
	std::cin>>n;
	for(int i=0;i<n;i++)
	{
		std::cin>>str;
		int pos=0,max=0,min=0;
		train.clear();
		train.push_back(str[0]);

		for(int k=1;k<str.size();k++)
		{
			if(str[k]=='-')
			{
				pos++;
			}
			else
			{
				pos--;
			}
			k+=2;
			if(pos>max)
			{
				train.push_back(str[k]);
				max=pos;
			}
			else if(pos<min)
			{
				train.push_front(str[k]);
				min=pos;
			}
		}
		
		while(!train.empty())
		{
			std::cout<<train.front();
			train.pop_front();
		}
		std::cout<<std::endl;
	}
	return 0;
}