#include <iostream>
#include <string>
#include <list>

int main()
{
	int n; std::cin >> n;
	for (int i=0; i<n; i++) {
		std::string input;
		std::cin >> input;
		std::list<char> cars;
		cars.push_back(input[0]);
		std::list<char>::iterator it = cars.begin();
		for (int k=3; k<input.length(); k+=3) {
			char c = input[k];
			bool right = (input.substr(k-2,2) == "->");
			if (right) {
				++it;
				if (it == cars.end()) {
					cars.push_back(c); it = cars.end(); --it;
				}
			}
			else {
				if (it == cars.begin()) {
					cars.push_front(c); it = cars.begin();
				}
				else --it;
			}
		}
		for (it = cars.begin(); it != cars.end(); ++it) {
			std::cout << *it;
		}
		std::cout << std::endl;
	}
				
	return 0;
}


