#include <iostream>
#include <string>
#include <list>
using namespace std;
int main()
{
  int n,i,l;
  string s;
  list<char> ls;
  list<char>::iterator is,ie;
  cin >> n;
  while(n--){
    ls.clear();
    cin >> s;
    ls.push_back(s[0]);
    l = s.length();
    is = ie = ls.begin();
    for(i=1; i<l; i+=3){
      string t = s.substr(i,2);
      if(t == "->" && *ie == s[i-1]){
	ls.push_back(s[i+2]);
	ie = ls.end();
	ie--;
      }else if(t == "<-" && *is == s[i-1]){
	ls.push_front(s[i+2]);
	is = ls.begin();
      };
    }
    is = ls.begin();
    while(is != ls.end()){
      cout << *is;
      is++;
    }
    cout << endl;
  }
  return 0;
}