#include <bits/stdc++.h>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define PB push_back

typedef pair<int, char> pic;
typedef vector<pic> vp;

int main() {
	int n;
	cin >> n;
	while (n--) {
		vp v;
		string str;
		cin >> str;
		
		v.PB(pic(0, str[0]));
		
		int tmp = 0;
		for(int i = 1; i < str.size(); i += 3) {
			if (str.substr(i, 2) == "<-") {
				tmp--;
				v.PB(pic(tmp, str[i + 2])); 
			}
			else {
				tmp++;
				v.PB(pic(tmp, str[i + 2]));
			}
		}
		sort(v.begin(), v.end());
		v.erase(unique(v.begin(), v.end()), v.end());
		
		REP(i, v.size())
			printf("%c", v[i].second);
		cout << endl;
	}
	return 0;
}