#include <iostream>
#include <stdio.h>
#include <string.h>
#include <list>

using namespace std;

int main() {
	char c[1025];
	int i,n,k;
	list<char> tr;
	list<char>::iterator it;
	cin >> n;
	for (n;n>0;n--) {
	  cin >> c; 
	  k=strlen(c);
	  tr.push_back(c[0]);
	  it=tr.begin();
	  for (i=0;i<k-3;i+=3) { 
		  if (c[i+1]=='-') {it++; if (it==tr.end()) { it--; tr.push_back(c[i+3]); it++;}}
		  else { if (it==tr.begin()) tr.push_front(c[i+3]); it--;}
	  }
	  for (it=tr.begin();it!=tr.end();it++) cout << *it; cout << endl;
	  tr.clear();
	}
	return 0;
}