#include <iostream>
#include <utility>
#include <vector>
#include <algorithm>
#include <cstdio>
using namespace std;
typedef pair<int, string> p;
int main() {
  int n;
  string str;
  scanf("%d\n",&n);

  for(int i=0;i<n;i++) {
    getline(cin,str);

    int pos = 27;
    vector<p> car;
    car.clear();
    for(unsigned int i=0;i<str.size();i+=3) {
      p  temp;
      temp.second=str.substr(i,1);
      temp.first = pos;
      car.push_back(temp);
      if(i==str.size()-1) break;
      if(str.substr(i+2,1) == ">") {
        pos++;
      }
      else {
        pos--;
      }
    }

    sort(car.begin(),car.end());
    if(car.size()!=0) {
      cout << car[0].second;
    }
    for(unsigned int i=1;i<car.size();i++) {
      if(car[i].second != car[i-1].second) {
        cout << car[i].second;
      }
    }
    cout << endl;
  }

}