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

int main(){
	int n,pos;
	char train[60];
	string s;
	cin >> n;
	getchar();
	for(int i = 0;i < n;i++){
		pos = 30;
		for(int j = 0;j < 60;j++) train[j] = 0;
		getline(cin,s);
		train[pos] = s[0];
		for(int j = 1;j < s.size();j++){
			if(s[j] == '-') {
				j += 2;
				train[++pos] = s[j];
			}
			else if(s[j] == '<'){
				j += 2;
				train[--pos] = s[j];
			}
		}
		for(int j = 0;j < 60;j++){
			if(train[j] != '\0') cout << train[j];
		}
		cout << endl;
	}
	return 0;
}