#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <utility>
using namespace std;

#define rep(i,n) for(int (i)=0; (i)<(int)(n); ++(i))
#define foreach(c,i) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)

string solve() {
  string in, ret;
  cin >> in;
  const int sz = in.size();
  ret.insert(0, 1, in[0]);
  for (int i = 0; i < sz; i+=3) {
    if (i == sz-1) {
      continue;
    } else {
      int l = -1;
      rep (j,ret.size()) if (in[i] == ret[j]) { l = j; break; }
      char c = in[i+3];
      if (in[i+2] == '>') {
        if (l == ret.size() - 1) {
          ret.insert(l+1, 1, c);
        }
      } else {
        if (l == 0) {
          ret.insert(l, 1, c);
        }
      }
    }
  }
  return ret;  
}

int main() {
  int n;
  cin >> n;
  rep (i,n) cout << solve() << endl;
  return 0;
}