#include<iostream>
#include<string>
using namespace std;
int main(){
  int n, cnt, min, max;
  char hoge[10000];
  cin >> n;
  cin.ignore();
  while(n--){
    cnt = 0, min = 0, max = 0;
    string num;
    cin >> num;
    for(int i=0;i<num.size();i++){
      if(num[i] == '>') cnt++;
      else if(num[i] == '<') cnt--;
      else if(num[i] != '-') hoge[cnt] = num[i];
      if(min > cnt) min = cnt;
      else if(max < cnt) max = cnt;
    }
    for(int i = min ; i <= max; i++){
      cout << hoge[i];
    }
    cout << endl;
  }
}