#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    int n;
    cin >> n;

    while(--n >= 0){
        string s;
        cin >> s;
        int m = s.size();

        deque<char> train(1, s[0]);
        int j = 0;
        for(int i=1; i<m; i+=3){
            if(s[i] == '<'){
                -- j;
                if(j < 0){
                    train.push_front(s[i+2]);
                    ++ j;
                }
            }else{
                ++ j;
                if(j == train.size())
                    train.push_back(s[i+2]);
            }
        }

        cout << string(train.begin(), train.end()) << endl;
    }
}