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

string solve(string s) {
	string ret = "";

	int indx = 0;
	for(int i = 0; i < s.size(); i++) {
		if(s[i] == '-')
			continue;
		else if(s[i] == '>') {
			indx++;
		}
		else if(s[i] == '<') {
			indx--;
		}
		else {
			if(indx < 0) {
				ret.insert(ret.begin(), s[i]);
				indx = 0;
			}

			else if(indx == ret.size()) {
				ret.push_back(s[i]);
			}
		}
	}

	return ret;
}

int main() {
	int n;

	cin >> n;
	for(int i = 0; i < n; i++) {
		string s;
		cin >> s;
		cout << solve(s) << endl;
	}

	return 0;
}