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

int main(){
  int i,j,k,n;
  string log;

  cin >> n;
  
  for( i=0;i<n;i++ ){
    char train[52]={NULL};
    int m=25;
    cin >> log;
    train[m]=log[0];
    for( j=3;j<log.size();j+=3 ){
      if(log[j-1] == '>'){
	m++;
	train[m] = log[j];
      }else{
	m--;
	train[m] = log[j];
      }
    }
    for(k=0;k<52;k++){
      if(train[k] >= 'a' && train[k] <= 'z' ){
	cout << train[k];
      }
    }
    cout << endl;
    log.erase();
  }

  return 0;
}