#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,i;
  string s,a;
  
  cin>>n;
  for(int j=0;j<n;++j){
  cin>>s;
  a=s[0];
  int pos=0;
  for(i=3;i<s.size();i+=3){
    if(s[i-1]=='>'){
      if(s[i]==a[pos+1]){
	pos++;
	continue;
      }
      a+=s[i];
      pos++;
    }else if(s[i-1]=='-'){
      if(s[i]==a[pos-1]){
	pos--;
	continue;
      }
      a=s[i]+a;
      pos--;
      if(pos<0) pos=0;
    }
  }
  cout<<a<<endl;
  }
  return 0;
}