#include<iostream>
#include<string>

using namespace std;

int main(){
  int i, j, n;
  string str, train;
  string::iterator iter;

  cin >> n;

  for(i=0; i<n; ++i){
    cin >> str;
    train.push_back(str[0]);

    for(j=1, iter=train.begin(); j<str.size(); j+=3){
      if(str[j] == '<' && str[j+1] == '-'){
	if(iter == train.begin()){
	  train.insert(train.begin(), str[j+2]);
	  iter = train.begin();
	}else{
	  --iter;
	}
      }else if(str[j] == '-' && str[j+1] == '>'){
	if(iter == train.end()-1){
	  train.push_back(str[j+2]);
	  iter = train.end()-1;
	}else{
	  ++iter;
	}
      }
    }

    cout << train << endl;
    train.clear();
  }

  return 0;
}