#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main() {

  int n;
  cin >> n;

  for(int q=0;q<n;q++) {
    string str;
    cin >> str;

    string train;

    train.clear();
    int ima = 0;
    int head = 0,tail=0;
    train += str[0];
    for(int i=0;i<str.size();i++) {

      if(str[i] == '>' ) {
	ima++;
	if(head < ima) {
	train += str[i+1];
	head = ima;
	}
      }
      else if(str[i] == '<'){
	ima--;
	if(tail > ima) {
	  tail = ima;
	  reverse(train.begin(),train.end());
	  train += str[i+2];
	  reverse(train.begin(),train.end());
	}
      }

    }
    
    cout << train << endl;

  }

  return 0;

}