#include<stdio.h>
#include<string>
#include<iostream>
using namespace std;

int main(){

char x,y,c,p[1025];
int N;
string str,S;
scanf("%d",&N);
for(int i=0;i<N;i++){
cin>>str;
int R=1024,L=1024,T=1024;
for(int i=0;i<str.size();i+=3)
{if(i==0)S=str[0];
else {
if(str[i-1]=='>'){T++;if(T>R){S=S+str[i];R=T;}}
else if(str[i-1]=='-'){T--;if(T<L){S=str[i]+S;L=T;}}
}
}
cout<<S<<endl;
}
return 0;
}