#include <iostream>
#include <map>

using namespace std;

int main()
{
    int n;
    
    cin >> n;
    while (n--) {
        string inp;
        map<int, char> m;
        int idx = 0;

        cin >> inp;

        m[idx] = inp[0];
        for (int i = 1; i < inp.size(); i += 3) {
            if (inp[i] == '-') 
                m[++idx] = inp[i + 2];
            else if (inp[i + 1] == '-') 
                m[--idx] = inp[i + 2];
        }
        
        map<int, char>::iterator it = m.begin();
        for ( ; it != m.end(); it++) 
            cout << (*it).second;
        cout << endl;
    }

    return 0;
}