#include <iostream>
#include <string>
#include <vector>
class Sharyou {
	Sharyou *prev, *back;
public:
	char ch;
	Sharyou(const char &c = ' ') :prev{ nullptr }, back{ nullptr }, ch{ c } {};
	void set_prev(Sharyou &p) {
		prev = &p;
	}
	void set_back(Sharyou &b) {
		back = &b;
	}
	std::string to_s() const {
		auto front = top();
		return front.to_string();
	}
private:
	Sharyou top() const {
		if (prev) {
			return prev->top();
		}
		else {
			return (*this);
		}
	}
	std::string to_string(std::string res = "") const {
		res.push_back(ch);
		if (back) {
			return back->to_string(res);
		}
		else {
			return res;
		}
	}
};
std::vector<Sharyou> init() {
	std::vector<Sharyou> vector(26);
	char ch = 'a';
	for (auto i = 0; i < 26; ++i, ++ch) {
		vector.at(i).ch = ch;
	}
	return vector;
}
int main() {
	int n;
	std::cin >> n;
	for (; n > 0; --n) {
		std::string str;
		std::cin >> str;
		std::vector<Sharyou> vector = init();
		for (auto i = 3; i < str.size(); i += 3) {
			switch (str.at(i - 1)) {
			case '>':
				vector.at(str.at(i) - 'a').set_prev(vector.at(str.at(i - 3) - 'a'));
				vector.at(str.at(i - 3) - 'a').set_back(vector.at(str.at(i) - 'a'));
				break;
			case '-':
				vector.at(str.at(i) - 'a').set_back(vector.at(str.at(i - 3) - 'a'));
				vector.at(str.at(i - 3) - 'a').set_prev(vector.at(str.at(i) - 'a'));
			}
		}

		std::cout << vector.at(str.at(0) - 'a').to_s() << '\n';
	}
}