 #include<iostream>
 #include<stdio.h>
 #include<string>
 #include<math.h>
 #include<iomanip>
 #include<algorithm>
 #include<string.h>
 #include<cctype>
 #include<map>
 #include<set>
 #include<vector>
 #include<sstream>
 #include<stack>
 #include<queue>
 #include<deque>
 #include<functional>
 #include<utility>
 
 using namespace std;

 int main()
 {
   int n;
   cin>>n;
   while(n--)
   {
     string s;
     int alpha[26]={0};
     deque<char> mm;
     deque<char>::iterator iter;
     cin>>s;
     mm.push_back(s[0]);
     alpha[s[0]-'a']++;
     for(int i=0;(i+3)<s.length();i=i+3)
     {
       if(s[i+1]=='-'&&s[i+2]=='>')
       {
         if(!alpha[s[i+3]-'a']) mm.push_back(s[i+3]);
         alpha[s[i+3]-'a']++;                                
       }
       else
       {
         if(!alpha[s[i+3]-'a']) mm.push_front(s[i+3]);
         alpha[s[i+3]-'a']++;     
       }        
     }          
     for(iter=mm.begin();iter!=mm.end();++iter)
     {
       cout<<(*iter);                                        
     }
     cout<<endl;
   } 
   //while(1);
   return 0;
 }

 