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

int main()
{
	int n,siz,ite,strite;
	string res,str;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> str;
		res = str[0];
		strite = 1;
		siz = 0;
		ite = 0;
		while (strite < str.size()) {
			if (str[strite] == '<') {
				if (ite == 0) {
					siz++;
					strite += 2;
					res = str[strite++] + res;
				} else {
					strite += 3;
					ite--;
				}
			}
			else if (str[strite] == '-') {
				if (ite == siz) {
					siz++;
					ite = siz;
					strite += 2;
					res += str[strite++];
				} else {
					strite += 3;
					ite++;
				}
			}
		}
		cout << res << endl;
	}
	return 0;
}