#include<iostream>
#include<string>
using namespace std;
int main(){
  string s;
  int n;
  cin>>n;
  for(int i=0;i<n;i++){
    string d;
    int in=0;
    cin>>d;
    s=d[0];
    for(int j=1;j<d.size();){
      if(d[j]=='-'&&in+1==s.size()){s+=d[j+2];in++;}
      else if(d[j]=='-')s[++in]=d[j+2];
      else if(in<=0)s=d[j+2]+s;
      else s[--in]=d[j+2];
      j+=3;
      //cout<<s<<endl;
    }
    cout<<s<<endl;
  }

}