#include<cstdio>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<cstdlib>
#include<iomanip>
#include<queue>
#include<set>
#include <valarray>
#include<stack>
#include<sstream>

using namespace std;

void Solution()
{
    int n;
    
    cin>>n;
    
    for(int i = 0; i < n; i++)
    {
        string s, str;
        
        cin>>s;
        
        int p=0;
        
        for(int j = 0; j < (int)s.size(); j++)
        {
            if(s[j] == '>')
            {
                p++;
            }
            else if(s[j] == '<')
            {
                p--;
            }
            else if('a' <= s[j] && s[j] <= 'z')
            {
                if(p == -1)
                {
                    str = s[j] + str;
                    
                    p = 0;
                }
                else if(p == (int)str.size())
                {
                    str = str + s[j];
                }
            }
        }
        
        cout<<str<<"\n";
    }
}

int main()
{
    Solution();
    return 0;
}