#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;

int main() {
	int n; cin >> n;
	rep(i, n) {
		string s; cin >> s;
		deque<char>que; que.push_back(s[0]);
		int pos = 0, look = 1;
		while (look + 2 < s.size()) {
			if (s[look + 1] == '>') {
				if (++pos >= que.size()) {
					que.push_back(s[look + 2]);
				}
			}
			else {
				if (pos - 1 < 0) {
					que.push_front(s[look + 2]);
				}
				else pos--;
			}
			look += 3;
		}
		for (char c : que) {
			cout << c;
		}
		cout << endl;
	}
}