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