#include<iostream>
#include<string>
#include<map>
#include<cstdio>
#include<cctype>
using namespace std;
int main(){
  int n,cnt;
  string str;
  map<int,char> data;
  cin >> n;
  while(n--){
    cnt = 0;
    cin >> str;
    for(int i=0,l=str.size();i<l;i++){
      if(isalpha(str[i])) data[cnt] = str[i];
      else if(str[i]=='<') cnt--;
      else if(str[i]=='>') cnt++;
    }
    for(map<int,char>::iterator it = data.begin(),l = data.end();it!=l;it++){
      cout << (*it).second;
    }
    cout << endl;
    data.clear();
  }
}