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

int main(){

  int n, len_str, len_vc, pos;
  string str;
  vector<char> vc;

  cin >> n;
  
  for(int i=0; i<n; i++){
    cin >> str;
    len_str = str.length();
    vc.clear();
    vc.push_back(str[0]);
    len_vc = 1;
    pos = 0;
  
    for(int j=1; j<len_str; j+=3){
      if(str[j] == '<'){
        if(pos != 0) pos--;
        else{
          vc.insert(vc.begin(), str[j+2]);
          len_vc++;
        }
      }
      else{
        if(pos != len_vc - 1) pos++;
        else{
          vc.push_back(str[j+2]);
          len_vc++;
          pos++;
        }
      }
    }
  
    for(int j=0; j<len_vc; j++){
      cout << vc[j];
    }
    cout << endl;
 
  }

  return 0;

}