#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef pair<char, char> P;

int main() {
  int N; cin >>N;
  REP(n, N){
    string str; cin >>str;
    if(str.length() == 1){
      cout <<str <<endl;
      continue;
    }
    map<char, P> m;
    set<char> s;
    for(int i = 0; i + 3 < (int)(str.length()); i += 3){
      char c = str[i], next = str[i + 3];
      if(s.find(c) == s.end()) m[c] = P('A', 'A');
      if(s.find(next) == s.end()) m[next] = P('A', 'A');
      s.insert(c);
      s.insert(next);
      if(str[i + 2] == '>'){
        m[c].second = next;
        m[next].first = c;
      } else{
        m[c].first = next;
        m[next].second = c;
      }
    }
    char now = 'A';
    for(map<char, P>::iterator it = m.begin(); it != m.end(); ++it) if(it->second.first == 'A') now = it->first;
    while(now != 'A'){
      cout <<now;
      now = m[now].second;
    }
    cout <<endl;
  }
  return 0;
}