#include <iostream>
#include <algorithm>
#include <list>
#include <cstdio>
using namespace std;

int main() {
  int Tc;
  scanf("%d", &Tc);
  scanf("%*c");
  while(Tc--) {
    char c;
    list<char> v;
    list<char>::iterator it;
    scanf(" %c", &c);
    v.push_back(c);
    it = v.begin();
    while(scanf("%c", &c), c != '\n') {
      scanf("%c", &c);
      if(c == '>') {
        ++it;
        if(it == v.end()) it = v.insert(it, ' ');
      } else {
        if(it == v.begin()) it = v.insert(it, ' ');
        else --it;
      }
      scanf("%c", &c);
      *it = c;
    }
    for(it = v.begin(); it != v.end(); ++it) printf("%c", *it);
    puts("");
  }
  return 0;
}