#include <string>
#include <iostream>
using namespace std;
int n; string s;
int main() {
	cin >> n;
	for(int i = 0; i < n; i++) {
		cin >> s;
		string t = s.substr(0, 1); int pos = 0;
		for(int i = 3; i < s.size(); i += 3) {
			if(s[i - 1] == '>') {
				if(pos + 1 == t.size()) t += s[i];
				pos++;
			}
			else {
				if(pos == 0) t = s[i] + t;
				else pos--;
			}
		}
		cout << t << endl;
	}
}