#include <iostream>
#include <cstdio>
#include <map>

using namespace std;

int main() {
  int N; cin >> N;
  for (int i = 0; i < N; i++) {
    map<int, char> m;
    int start = 0;
    int end = 0;
    int pos = 0;
    string train;
    cin >> train;
    m[0] = train[0];
    for (unsigned int i = 1; i < train.size(); i+=3) {
      char c = train[i+2];
      if (train[i+1] == '>') pos++;
      else pos--;
      m[pos] = c;
      if (pos < start) start = pos;
      if (end < pos) end = pos;
    }
    for (int i = start; i <= end; i++) {
      cout << m[i];
    }
    cout << endl;
  }


  return 0;
}