#include <iostream>
#include <string>
#include <deque>
using namespace std;

int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		string line;
		cin >> line;
		deque<char> t;
		t.push_back(line[0]);
		unsigned index = 0;
		for (unsigned i = 1; i < line.size(); i++) {
			switch (line[i]) {
			case '-':
				i += 2;
				index++;
				if (index == t.size()) {
					t.push_back(line[i]);
				}
				break;
			case '<':
				i += 2;
				if (index == 0) {
					t.push_front(line[i]);
				}
				else index--;
			}
		}
		for (unsigned i = 0; i < t.size(); i++) {
			cout << t[i];
		}
		cout << endl;
	}
	return 0;
}