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

int main()
{
	int n;
	std::cin >> n;
	
	while( n-- )
	{
		std::string s;
		std::cin >> s;

		std::deque<char> deq;
		deq.push_back( s[0] );
		
		int p = 0;
		
		for( int i = 1; i < s.size(); i += 3 )
		{
			if( s[i] == '<' && !(p--) )
				deq.push_front( s[i+2] ), ++p;
			else if( s[i+1] == '>' && ++p == deq.size() )
				deq.push_back( s[i+2] );
		}

		for( auto it = deq.begin(); it != deq.end(); ++it )
			std::cout << *it;

		std::cout << std::endl;
	}

	return 0;
}