#include<vector>
#include<list>
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int main(){
  int i,j;
  int len,n;
  vector<string> u;
  list<string> a;
  cin>>n;
  for(i=0;i<n;i++){
    string s;
    cin>>s;
    u.push_back(s);
  }
  for(i=0;i<n;i++){
    a.clear();
    a.push_back(u[i].substr(0,1));
    len=u[i].length();
    for(j=1;j<len;j+=3){
      if(u[i][j+1]=='>'){
	if(u[i].substr(j-1,1)==a.back())
	  a.push_back(u[i].substr(j+2,1));
      }else if(u[i][j]=='<'){
	if(u[i].substr(j-1,1)==a.front())
	  a.push_front(u[i].substr(j+2,1));
      }
    }
    list<string>::iterator it=a.begin();
    for(;it!=a.end();it++)
      cout<<*it;
    cout<<endl;
  }
  return 0;
}