#include <iostream>
#include <map>
int main(){
	int n;
	std::cin >> n;
	std::string s;
	while(n--, std::cin >> s){
		int pos = 0;
		while(pos = s.find("-", pos), pos != std::string::npos){
			s.replace(pos, 1, "");
		}

		std::map<char, char> m, rm;
		for(int i=1;i<s.size();i+=2){
			if(s[i] == '>')
				m[s[i+1]] = s[i-1], rm[s[i-1]] = s[i+1];
			else
				m[s[i-1]] = s[i+1], rm[s[i+1]] = s[i-1];
		}

		char end = (*m.begin()).first;
		std::cout << end << std::endl;
		while(m[end] != 0){
			end = m[end];
		}
		//whileI¹_ÅendÍstartÆÈé

		while(rm[end] != 0){
			std::cout << end;
			end = rm[end];
		}
		std::cout << end << '\n';
	}
}