#include<bits/stdc++.h>
using namespace std;

int main(){
  int n;
  string str;
  map<int,char>data;
  int cnt;

  cin >> n;
  
  while(n--){
    cnt = 0;
    cin >> str;
    for(int i = 0;i < str.size();i++){
      if(isalpha(str[i]))data[cnt] = str[i];
      if(str[i] == '>')cnt++;
      if(str[i] == '<')cnt--;
    }

    for(map<int,char>::iterator it = data.begin();it != data.end();it++){
      cout << it->second;
    }
    cout << endl;
    data.clear();
  }
}